Populating the “Ref” in mongoose schema while working with Graphql

前端 未结 2 425
刺人心
刺人心 2021-01-15 00:21

I am working with Graphql and then I come to a situation where I need to populate, but I am not getting how to excute that.

Here is my Booking schema

         


        
相关标签:
2条回答
  • 2021-01-15 00:46

    I have never made anything like this before but after saving new Booking here:

    const result = await booking.save();
    

    You can use .populate() on result. Example:

    await result.populate("user");
    

    Or if the above not work:

    await result.populate("user").execPopulate();
    
    0 讨论(0)
  • 2021-01-15 00:51

    I hope it may help you.

    const result = await booking.save();
    const res=await booking.findById(result._id).populate("user");
    console.log(res)
    
    0 讨论(0)
提交回复
热议问题