Search code examples
mongodbaggregation-frameworklookupmongoose-schema

In mongodb. I have One object inside ids of user array , Now I want to lookup for that ids in related users details, with aggregation


  {
        "_id": "61efc2c437c455b7216629ff",
        "event_images": [
            "1643102858880rn_image_picker_lib_temp_38cdc02f-4207-446a-9263-1e6914954095.jpg"
        ],
        "distance": 80,
        "ratio_men": 50,
        "ratio_women": 60,
        "ratio_others": 30,
        "invite_users": [
            "61e6830ae88d1929e3d239f9",
            "61e6830ae88d1929e3d239f9",
            "615ae0e5da07c2f5d777248b",
            "615ae0e5da07c2f5d777248b",
            "61e7beaae88d1929e3627c69",
            "61e7beaae88d1929e3627c69"
        ],
        "notinvited_users": [],

I have Invited user array inside the array i have ids, I want to lookup the user detail with these ids


Solution

  • do it yourself you can do it you have extreme knowledge of this

    or you can try this

    const userData = await Event.find({ _id : ObjectId(ID) , payment_status : 1 }).populate('invite_users' , {firstname:1})