sql >> Database >  >> NoSQL >> MongoDB

Kan Mongoose.js Subdocument Array niet vullen

probeer dit

    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
                 });
             });


  1. Werken geospatiale query's op arrays? ($geoWithin, $geoIntersects)

  2. mongodb-org conflicteert met mongodb-10gen-server

  3. Pymongo-aggregaat:filter op aantal velden (dynamisch)

  4. Hoe gebruik je een variabele als veldnaam in mongodb-native findAndModify?