Skip to content
New issue

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

populate is not working! #97

Open
toufik2015 opened this issue May 31, 2022 · 1 comment
Open

populate is not working! #97

toufik2015 opened this issue May 31, 2022 · 1 comment

Comments

@toufik2015
Copy link

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 toufik2015 changed the title The pre hook is not working! populate is not working! May 31, 2022
@vkarpov15
Copy link
Member

@toufik2015 what version of Mongoose?

Also, why are you reporting this issue here? It doesn't look like you're using mongoose-autopopulate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants