I need some help to populate on sub-document with mongoose, I searched a lot in the internet , but didn't find a way to fix my problem.
I heve two schema : 1 - InfraServer
var InfraServerSchema = new Schema({ _id : String, equipe : String, servidor : String, memoria : String, processador : String, modelo : String, so : String, usuario : String },{ collection: 'infraserver' }); var InfraServer = mongoose.model('InfraServer', InfraServerSchema); module.exports = InfraServer; 2 - InfraDataBase
var InfraDataBaseSchema = new Schema({ _id : String, equipe : String, nome_base : String, vipname : String, tipo_banco : String, versao: String, servidores : [{ type : mongoose.Schema.Types.ObjectId, ref: 'InfraServer' }], tnsnames : String },{ collection: 'infradatabase' }); var InfraDataBase = mongoose.model('InfraDataBase', InfraDataBaseSchema); module.exports = InfraDataBase; I'm trying to populate the array servidores like below, in routes folder, but when I print seeds variable, the array return empty, and need the servidores.servidor (field in InfraServer), servidores._id are populate correctly.
InfraDataBase.find().where('equipe').in(req.session.userInf.equipe).populate('servidores').exec(function(err, seeds){ if( err || !seeds) console.log("No seeds found"); else { console.log("--->>> " + seeds); } Can help me find a way to resolve this problem .
Tks