I'm using mongoose 4.6.6, express 4.13, passport 0.3.
I have the next mongoose Schema
var userSchema = new Schema({
nombre: String,
apellidos: String,
email: String,
pass: String,
fecha_registro : { type: Date, default: Date.now },
rol_list: [Schema.Types.ObjectId], // generic array of objectId
deleted: {type: Boolean, default: false}
});
module.exports = mongoose.model('User', userSchema);
When I search a user and try to populate the "rol_list" array, is always empty. I have looked in mongo the users are well filled, but mongoose return it empty.
passport.deserializeUser(function(id, done) {
User.findById(id)
.populate('rol_list')
.exec(function(err, user) {
console.log(user);
done(err, user);
});
});
The console.log(user) show always the array rol_list empty.
If I assign a reference to the ObjectId like:
rol_list: [{ type: Schema.Types.ObjectId, ref: 'Rol1' }]
than is correct filled, logically only with the element "Rol1".
Any idea?
rol_list
? – Orelsanpls