📜  在 mongoose 中填充示例 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:08.010000             🧑  作者: Mango

代码示例2
const Live = new Schema(
  {
    user_id:{         // this one populate
            type: Schema.Types.ObjectId,      
            ref: 'User',    //  User Schema
            required: true                 
        },
        title: {
            type: String,
        },
        category:{        // this one populate
            type: Schema.Types.ObjectId,
            ref: 'Category'  // Category Schema
        },
  }
)
let vid = await Live.find({})
            .populate({path:'user_id',select:'name image -_id'})
            .populate({path:'category',select:'category -_id',model:Category})