I need help to fill out a sub-document using mongoose, I searched a lot on the Internet but could not find a way to fix my problem.
I see two schemes: 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 try to fill in the servidores of the array, as shown below, in the routes folder, but when I print the seed variable, the array returns empty and I need servidores.servidor (field in InfraServer), servidores._id is filled 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); }
May help me find a way to solve this problem.
Tks