Collection inside collection as an array

i have 2 collection of user with 50 fields and user_details with 50 fields and i want to save user_details inside user collection as an Array how can i do that ?

Hi @Aniket_Zapatkar ,

What is the connecting field between the collections? If its for example _id in user and userId in user_details here is an aggregation to do it :

db.user.aggregate([
   {
      $lookup:
         {
           from: "user_details",
           localField: "_id",
           foreignField: "userId",
           as: "user_details"
         }
   },
   {
    $merge: {
        into: "user",
        on: "_id",
        whenMatched: "replace",
        whenNotMatched: "discard"
    }
   }
])

Thanks
Pavel

both collection have user_id in comman