Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

populate example in mongoose

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

 
PREVIOUS NEXT
Tagged: #populate #mongoose
ADD COMMENT
Topic
Name
3+5 =