I have three models. And i need to get the admin group name of a user
User
var userSchema = new mongoose.Schema({
// ...
roles: {
admin: { type: mongoose.Schema.Types.ObjectId, ref: 'Admin' }, // path 1
},
});
Admin
var adminSchema= new mongoose.Schema({
// ...
groups: [{ type: String, ref: 'AdminGroup' }], // path 2
});
AdminGroup
var adminGroupSchema = new mongoose.Schema({
// ...
name: { type: String, default: '' }, // need to get this field
});
In Mongoose
User.findById(req.user._id)
.populate({path: 'roles.admin', populate:{ path: 'groups'}})
.exec(function (err, adminGroups) {...}
When I try to call in my template {{adminGroups.name}}
it returns the name
of Admin
model, which also has a name
field, instead of AdminGroup
model.
I am usung Mongoose 4.9.0 so it must have support for deep population.
Thanks.