I have the following schema Thing:
{ name: "My thing", files: [ { name: "My file 1", versions: [ { file_id: ObjectId("blahblahblah") }, { file_id: ObjectId("blahblahblah") }, ], }, { name: "My file 2", versions: [ { file_id: ObjectId("blahblahblah") }, { file_id: ObjectId("blahblahblah") }, ], } ] } And then I a have a File schema:
{ _id: ObjectId("blahblah"), type: "image", size: 1234, } The file_id in the Thing schema is a REF to the _id of the File schema.
I want to $lookup all the files inside my Thing. So I started with this:
{ "$lookup": { "from": "files", "let": { "files": "$files" }, "pipeline": [ { "$match": { "$expr": { "$in": [ "$_id", "$$files.versions.file_id" ] } } }. ], "as": "files.versions.file" } } But it's obviously wrong. Can someone help?