Mongoose - using Populate on an array of ObjectId

后端 未结 2 683
旧时难觅i
旧时难觅i 2020-12-05 02:25

I\'ve got a schema that looks a bit like:

var conversationSchema = new Schema({
    created: { type: Date, default: Date.now },
    updated: { type: Date, de         


        
2条回答
  •  借酒劲吻你
    2020-12-05 02:54

    For anyone else coming across this question.. the OP's code has an error in the schema definition.. it should be:

    var conversationSchema = new Schema({
        created: { type: Date, default: Date.now },
        updated: { type: Date, default: Date.now },
        recipients: [{ type: Schema.ObjectId, ref: 'User' }],
        messages: [ conversationMessageSchema ]
    });
    mongoose.model('Conversation', conversationSchema);
    

提交回复
热议问题