MongoDB
 sql >> Base de Dados >  >> NoSQL >> MongoDB

Não é possível preencher a matriz de subdocumentos Mongoose.js


tente isso
    SubSchema = new Schema({
        _member:     {type: ObjectId, ref: 'Member'},
        members:     [{type: ObjectId, ref: 'Member'}],
        created:     { type: Date, default: Date.now }
    });
    var SubModel = mongoose.model('SubModel', SubSchema);//add

    MainSchema = new Schema({
        _member:     {type: ObjectId, ref: 'Member'},
        subs:        [SubSchema],
        members:     [{type: ObjectId, ref: 'Member'}],
        created:     { type: Date, default: Date.now }
    });

    var MainModel = mongoose.model('MainModel', MainSchema);

    MainModel.find({})
             .sort('created', -1)
             .limit(25)
             .populate("_member")
             .populate("subs._member")
             .exec(function(err, mains){

                 //add
                 SubModel.populate(mains,{
                     path:'subs.members'
                 },function(err,mains){
                    //mains[0].subs[0].members - is not empty
                 });
             });