mongoose 的 pupolate 联表查询

const friendSchema = new mongoose.Schema({
    userID: String,    //用户id
    friend_list: Array,
    group_list: {
        A: [
            { "id": { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, "nickName": String }
        ],
        B: [
            { "id": { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, "nickName": String }
        ],
        C: [
            { "id": { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, "nickName": String }
        ],
        D: [
            { "id": { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, "nickName": String }
        ]
    }
})
module.exports = mongoose.model("friend", friendSchema);

这种数据结构 mongoose 怎么用 populate 联表查询填充id字段

阅读 1.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进