The $lookup
stage will return an array of subdocuments. But the only value that I am interested in from the result of the $lookup
is the the _id
value. So instead of an array of { _id: ObjectId() }
, how do I flatten this array into just an array of ObjectId: [ ObjectId(), Objectid(), ... ]
2
Answers
Aggregation :
Output : returns ID in array (we can have mongodb objectId) but i have used simple numeric ID
You can simply map the array of subdocuments, using
$map
, like this:Playground link