我只想从以下集合中获取状态为“ ac”的用户。下面是我的样本集合。
我的收藏集
{
"_id" : ObjectId("5c480da48e80b74fa0a35fff"),
"exercise" : [],
"name" : "Challenge 03",
"groups" : [
{
"_id" : ObjectId("5c480dbe8e80b74fa0a36000"),
"hostGroup" : {
"groupId" : ObjectId("5c471a9f6d70c44d642e414f"),
"status" : "in",
"date" : ISODate("2019-01-23T06:46:22.366Z"),
"users" : [
{
"_id" : ObjectId("5c480dbe8e80b74fa0a36002"),
"usersId" : ObjectId("5c4719a76d70c44d642e413d"),
"date" : ISODate("2019-01-22T13:31:05.021Z"),
"status" : "in"
},
{
"_id" : ObjectId("5c480dbe8e80b74fa0a36001"),
"usersId" : ObjectId("5c4719bb6d70c44d642e413e"),
"date" : ISODate("2019-01-22T13:31:05.021Z"),
"status" : "ac"
}
]
}
}
],
"__v" : 0
}
我尝试过的查询
db.challenge.find({
"groups.hostGroup.users.status": "ac"
}, {
name: 1,
"groups.hostGroup.users.status": 1
})
我只希望记录状态为“ ac”的记录,而不应该返回状态为“ in”的文档。
期望输出
{
"_id" : ObjectId("5c480da48e80b74fa0a35fff"),
"exercise" : [],
"name" : "Challenge 03",
"groups" : [
{
"_id" : ObjectId("5c480dbe8e80b74fa0a36000"),
"hostGroup" : {
"groupId" : ObjectId("5c471a9f6d70c44d642e414f"),
"status" : "in",
"date" : ISODate("2019-01-23T06:46:22.366Z"),
"users" : [
{
"_id" : ObjectId("5c480dbe8e80b74fa0a36001"),
"usersId" : ObjectId("5c4719bb6d70c44d642e413e"),
"date" : ISODate("2019-01-22T13:31:05.021Z"),
"status" : "ac"
}
]
}
}
],
"__v" : 0
}