We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The pre hook is not working! and it doesn't populate the teacher field.
`const mongoose = require('mongoose');
const assignmentSchema = new mongoose.Schema( { teacher: { type: mongoose.Schema.ObjectId, ref: 'User' }, group: { type: mongoose.Schema.ObjectId, ref: 'Group' }, AssignedAt: { type: Date, default: Date.now() }, }, { toJSON: { virtuals: true }, toObject: { virtuals: true } } );
const Assignment = mongoose.model('Assignment', assignmentSchema);
assignmentSchema.pre(/^find/, function (next) { console.log('is this running?'); this.populate({ path: 'teacher', select: 'firstName', }); next(); });
module.exports = Assignment;`
The text was updated successfully, but these errors were encountered:
@toufik2015 what version of Mongoose?
Also, why are you reporting this issue here? It doesn't look like you're using mongoose-autopopulate
Sorry, something went wrong.
No branches or pull requests
The pre hook is not working! and it doesn't populate the teacher field.
`const mongoose = require('mongoose');
const assignmentSchema = new mongoose.Schema(
{
teacher: { type: mongoose.Schema.ObjectId, ref: 'User' },
group: { type: mongoose.Schema.ObjectId, ref: 'Group' },
AssignedAt: { type: Date, default: Date.now() },
},
{ toJSON: { virtuals: true }, toObject: { virtuals: true } }
);
const Assignment = mongoose.model('Assignment', assignmentSchema);
assignmentSchema.pre(/^find/, function (next) {
console.log('is this running?');
this.populate({
path: 'teacher',
select: 'firstName',
});
next();
});
module.exports = Assignment;`
The text was updated successfully, but these errors were encountered: