MongoDB-文档的查询数组

MongoDB-文档的查询数组,mongodb,Mongodb,嗨,我现在有一个像这样的文档集合 { "_id" : ObjectId("5a5f814487c320156094c144"), "sender_id" : "123", "iso_number" : "ABC-DEF-123", "subject" : "Sample Memo", "content" : "This is a sample memorandum sent through postman.", "recipients" : [

嗨,我现在有一个像这样的文档集合

 {
    "_id" : ObjectId("5a5f814487c320156094c144"),
    "sender_id" : "123",
    "iso_number" : "ABC-DEF-123",
    "subject" : "Sample Memo",
    "content" : "This is a sample memorandum sent through postman.",
    "recipients" : [ 
        {
            "faculty_number" : 222,
            "_id" : ObjectId("5a5f814487c320156094c146"),
            "status" : "Sent"
        }, 
        {
            "faculty_number" : 111,
            "_id" : ObjectId("5a5f814487c320156094c145"),
            "status" : "Seen"
        }
    ],
    "memo_created" : ISODate("2018-01-17T17:00:52.104Z"),
    "__v" : 0
}
所以如果我使用

db.collection.find({“recipients.faculty_number”:111,“recipients.status:“Sent”})

上面显示的此文档不应返回,因为我希望获取具有以下条件的所有文档:您需要的文档编号为111且状态为“已发送”

,此操作员将检查
收件人数组中每个文档的这两个条件

db.collection.find({"recipients": { $elemMatch: { "faculty_number": 111, "status": "Sent"} }})

我在发布了这篇文章之后就偶然发现了这个解决方案。非常感谢你!