Aggregation Pipeline(merge the collection if ids match)

I have two collections
collection1 => { userData : [
{fieldId:ObjectId('63b422210b0d84048e4cc401'), fieldValue:"123"},
{fieldId:ObjectId('63b422210b0d84048e4cc404'), fieldValue:"value2"}
]}

collection2: fieldresult : [{
  _id: ObjectId('63b422210b0d84048e4cc401'),
  title: "Field1",
  fieldType:"text",
  dataType: "String"
}, {
  _id: ObjectId('63b422210b0d84048e4cc404'),
  title: "Field2",
  fieldType:"text",
  dataType: "String"
}]

The required output is: 

output: [{
    _id: ObjectId('63b422210b0d84048e4cc401'),
    title: "Field1",
    fieldType:"text",
    dataType: "String",
    fieldValue:"123"
  },
  {
    _id: ObjectId('63b422210b0d84048e4cc404'),
    title: "Field1",
    fieldType:"text",
    dataType: "String",
    fieldValue:"value2"
  }]

Please share what you have tried and how it failed to deliver the desired result.

This will help us help you so that we avoid going in a direction that you already is wrong. Something just a little tweak of what you have is the solution.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.