Answers for "mongoose create then populate"

1

mongoose create populate response

let user = await User.create({ ... })
user = await user.populate('company').execPopulate()
Posted by: Guest on October-20-2020
0

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})
Posted by: Guest on January-11-2022

Code answers related to "mongoose create then populate"

Code answers related to "Javascript"

Browse Popular Code Answers by Language