Open toufik2015 opened 2 years ago
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;`
@toufik2015 what version of Mongoose?
Also, why are you reporting this issue here? It doesn't look like you're using mongoose-autopopulate
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;`