MongoDB match array based on document value [duplicate]
问题 This question already has answers here : Retrieve only the queried element in an object array in MongoDB collection (14 answers) MongoDb query condition on comparing 2 fields (4 answers) Closed 10 months ago . Let's say I have the following document structure: { "A": { "_id": "ID0" }, "B": [ "a": { "_id": "ID0", "field": "X" }, "b": { "_id": "ID1", "field": "Y" } ] } I want to project B matched with the _id in A . The end result would be: { "B": [ "a": { "_id": "ID0", "field": "X" } ] } I