skip to Main Content

MongoDB Aggregation – Flatten resultat

db.collection.aggregate([ .... { $group: {_id: "$data.r.id", "col": {$first: "$data.r"}}}, {$project:{"o":{"$objectToArray":"$col"}}}, {$unwind:"$o"}, {$group:{"_id":null, "keys":{$addToSet:"$o.k"}}}, {$project: {"keys":1, "_id": 0}}, {$addFields: {res:{$map:{ input:"$keys", as: "a", in: {"_id":0,"label": "$$a"}}}}}, {$project: {"res":1}} ]) With my MongoDB query, the output is: { "res" : [ {…

VIEW QUESTION
Back To Top
Search