함건주
함건주

Reputation: 45

mongo aggregation $facet and grouping ask

My aggregation is this.

enter image description here

These are result..

enter image description here

I wanna get bottom result.

enter image description here

How to aggregate this result ?

Upvotes: 2

Views: 4460

Answers (1)

Ashh
Ashh

Reputation: 46441

You can use $project, $unwind and $replaceRoot aggregation pipeline stages after $facet

db.collection.aggregate([
  { "$project": {
    "data": { "$concatArrays": ["$all", "$part"] }
  }},
  { "$unwind": "$data" },
  { "$replaceRoot": { "newRoot": "$data" } }
])

Upvotes: 8

Related Questions