I'm using native mongodb driver on nodejs and I wish to be able to run a single query and retrieve all documents from another collection.
I have a tags
collection: id_
, tag
and on my article collection I have tags
that is an array of ObjectId
now, when I retrieve the correct document I wish to have tags
holding the tag
value on the tags
collection.
I can't wrap my head around that, I've been trying this but it only retrieves the first tag:
db.orders.aggregate([
{
$unwind: "$tags"
},
{
$lookup:
{
from: "tags",
localField: "tags",
foreignField: "_id",
as: "tags_found"
}
},
{
$match: { "tags_found": { $ne: [] } }
}
])
Is there a way to retrieve all the tags at once? If not, what is the best way to do so without using Mongoose but the native driver?