good day.
There are two collections, such as:
db.tags.find() {_id:ObjectID(...),"text":"text1", "tags":"tag1"}, {_id:ObjectID(...),"text":"text2", "tags":["tag2", "tag3"]}, {_id:ObjectID(...),"text":"text3", "tags":["tag1", "tag3"]} and
db.tagdetails.find() {_id:ObjectID(...),"tagname":"tag1","det":"x"}, {_id:ObjectID(...),"tagname":"tag2","det":"y"} do $ lookup:
db.tags.aggregate([{$project:{_id:0, tags:1, text:1}}, {$unwind:"$tags"}, {$lookup: {from:"tagdetails", localField:"tags", foreignField:"tagname", as:"t"}}]) everything seems to work, but the output is a collection like this:
{"text":..., "tags":..., "t": [{"_id":..., "tagname":..., "det":...}]} more details:
{"text":"posttext", "tags":"tag1", "t":[{"_id":ObjectID..., "tagname": "tag1", "det":"x"}]} {"text":"posttext2", "tags":"tag2", "t":[{"_id":ObjectID..., "tagname": "tag2", "det":"y"}]} {"text":"posttext2", "tags":"tag3", "t":[]} {"text":"posttext3", "tags":"tag1", "t":[{"_id":ObjectID..., "tagname": "tag1", "det":"x"}]} {"text":"posttext3", "tags":"tag3", "t":[]} Ie, clearly, lukap puts the document from the second collection entirely. I do not need it. need to get a document of the form:
{"text":..., "tags":..., "det":...} Those. There is only one field from the second collection. I can not figure out how to do it. I cannot exclude it using $ project, an error appears:
The top-level _id field is the only field currently supported for exclusion
...and write down these fields. Also tell me how many elements are in the array after$lookup? - styvane...in the place of them. Some non-opaque MongoDB users would like to check their local response before writing it on the site. I know what I'm talking about - styvane