Can't get Mongoose.js Subdocument Array to populate

前端 未结 5 376
孤独总比滥情好
孤独总比滥情好 2021-02-04 06:23

I\'m using mongoose.js on a node.js server connecting to mongodb and I have a mongoose model like the following

SubSchema = new Schema({
    _member:     {type:          


        
5条回答
  •  孤城傲影
    2021-02-04 06:45

    I have something that looks a slightly different but populates the document with the array items. I'm wondering if it's the objectid's that are causing the issues.

    var mongoose = require('mongoose');
    var Schema = mongoose.Schema, ObjectID = Schema.ObjectId;
    
    var SubSchema = new Schema({
        testsub: String,       
        created: { type: Date, default: Date.now }
    });
    
    var MainSchema = new Schema({
        test: String
        subs: [SubSchema],
        created: { type: Date, default: Date.now }
    });
    
    mongoose.model('MainSchema', MainSchema, mainschema);
    
    var query = MainSchema.find({});
    

提交回复
热议问题