0

basically i dont want to project any key as out put, simply object i am getting from lookup join...

Here is my code:

PodMembers.aggregate([
  { $match: { instaid: ObjectId('5a27ed8e1990c12cc0310996'), datetime: { $exists: true } } },
  {
    $lookup: {
      from: "pods",
      localField: "pod_id",
      foreignField: "_id",
      as: "podinfo"
    }
  },
  { $unwind: "$podinfo" },
  {
    $group: {
      _id:"$podinfo"
    }
  },
  { $addFields: { Status: true } }
])

And i got following output:

enter image description here

Ashh
  • 44,693
  • 14
  • 105
  • 132
SGR Dalal
  • 121
  • 13

1 Answers1

2

You can use $replaceRoot (aggregation) to replace your root element

PodMembers.aggregate([
  { "$match": { "instaid": ObjectId('5a27ed8e1990c12cc0310996'), "datetime": { "$exists": true } } },
  { "$lookup": {
    "from": "pods",
    "localField": "pod_id",
    "foreignField": "_id",
    "as": "podinfo"
  }},
  { "$unwind": "$podinfo" },
  { "$group": {
    "_id":"$podinfo"
  }},
  { "$replaceRoot": { "newRoot": "$_id" } },
  { "$addFields": { Status: true } }
])
SGR Dalal
  • 121
  • 13
Ashh
  • 44,693
  • 14
  • 105
  • 132