在以下集合中,我们希望获取所有“ approved”字段值为false的团队。如果查询工作正常,我们应该得到2个对象。
{
"categories": [],
"round": 0,
"questionNumber": 0,
"roundStarted": false,
"roomOpened": false,
"gameEnded": false,
"_id": "5f898e467405e4051439e0c1",
"roomCode": 1234,
"teams": [
{
"score": 0,
"approved": false,
"answerCorrect": false,
"_id": "5f898e467405e4051439e0c2",
"name": "Alex"
},
{
"score": 0,
"approved": false,
"answerCorrect": false,
"_id": "5f898e467405e4051439e0c3",
"name": "Ritse"
},
{
"score": 0,
"approved": true,
"answerCorrect": false,
"_id": "5f898e467405e4051439e0c4",
"name": "Fritz"
}
]
}
我们已经尝试了以下方法,但是我们仍然获得了所有真实的结果。
const result = await Room.find({ $and: [{ roomCode: { $eq: req.params.id } },
{ 'teams.approved': false } ] }, {teams: 1})
查询结果:
[
{
"_id": "5f898e467405e4051439e0c1",
"teams": [
{
"score": 0,
"approved": false,
"answerCorrect": false,
"_id": "5f898e467405e4051439e0c2",
"name": "Alex"
},
{
"score": 0,
"approved": false,
"answerCorrect": false,
"_id": "5f898e467405e4051439e0c3",
"name": "Ritse"
},
{
"score": 0,
"approved": true,
"answerCorrect": false,
"_id": "5f898e467405e4051439e0c4",
"name": "Fritz"
}
]
}
]
我如何确保只得到前两个对象?