1

I am a starter with mean stack, i want to nested object with another collection in mongoose, my product collection look as follows, it contain multiple bidders(users)

{
        "_id": "5a16b3774d74d10ce0131254",
        "name": "my test product",
        "desc": "looking good",
        "bid_amount": 120,
        "bidders": [
            {
                "amount": "145",
                "bid_status": "participated",
                "user_id": "5a1b9f8c356e9d246c0443ac"
            },
            {
                "amount": "160",
                "bid_status": "rejected",
                "user_id": "5a1be6c7356e9d246c0443af"
            }
        ]
}

my user collection as follows

[
    {
        "_id": "5a1b9f8c356e9d246c0443ac",
        "name": "abcd",
        "email": "abcd@gmail.com"
    },
    {
        "_id": "5a1be6c7356e9d246c0443af",
        "name": "xyz",
        "email": "xyz@gmail.com"
    },

]

I need each user details corresponds to its object, not a separate object array, I am looking a result like this using mongoose

 [
    {
       "_id": "5a16b3774d74d10ce0131254",
        "name": "my test product",
        "desc": "looking good",
        "bid_amount": 120,
        "bidders": [
            {
                "amount": "145",
                "bid_status": "participated",
                "user_id": "5a1b9f8c356e9d246c0443ac",
                "user_details" : {
                    "_id": "5a1b9f8c356e9d246c0443ac",
                    "name": "abcd",
                    "email": "abcd@gmail.com"
                }
            },
            {
                "amount": "160",
                "bid_status": "rejected",
                "user_id": "5a1be6c7356e9d246c0443af",
                "user_details": {
                    "_id": "5a1be6c7356e9d246c0443af",
                    "name": "xyz",
                    "email": "xyz@gmail.com"
                }
            }
     }
]
YasirPoongadan
  • 683
  • 6
  • 19

0 Answers0