如何查询只返回房间的学生:102岁,年龄> = 18? 我希望获得如下输出:
{
"name": "john",
"age": 21,
"books": [
{
"title": "algebra",
"pages": 300,
"author": "Jkrowling"
}
]
}
并提供以下文件
{
"teacher": "teachername",
"room": 102,
"students": [
{
"name": "john",
"age": 21,
"books": [
{
"title": "algebra",
"pages": 300,
"author": "Jkrowling"
}
]
}
]
}
答案 0 :(得分:0)
以下聚合将有助于
db.collectionName.aggregate({"$unwind":"$students"},
{"$match":{"room":102,"students.age":{"$gt":18}}}).pretty()