I made some MongoDB aggregation like this:
db.first_collection.aggregate(
[
{ $lookup: {
from:"second_collection",
localField:"fisrt_id",
foreignField:"second_id",
as:"result"
}
},
{ $redact: {
$cond: {
if: { "$eq": [ "$result", [] ] },
then: "$$DESCEND",
else: "$$PRUNE"
}
}
},
]
)
The output is:
{ "_id" : ObjectId("5a32249969e74c004161acc8"), "name" : "n1", "createdAt" : ISODate("2017-12-14T07:13:28.048Z"), "updatedAt" : ISODate("2017-12-14T07:13:28.048Z"), "result" : [ ] }
{ "_id" : ObjectId("5a69a60382e7d3002e6c7c74"), "name" : "n2", "createdAt" : ISODate("2018-01-25T09:40:19.098Z"), "updatedAt" : ISODate("2018-01-25T09:43:46.508Z"), "result" : [ ] }
Instead of Objects, I need an array containing only IDs. like:
["5a32249969e74c004161acc8", "5a69a60382e7d3002e6c7c74"]
Please let me know how?