Mongodb:聚合嵌套文档,数组匹配
如何使用MongoDB聚合预测至少有2位作者,最多3位作者的书名 提前谢谢Mongodb:聚合嵌套文档,数组匹配,mongodb,aggregation-framework,document,Mongodb,Aggregation Framework,Document,如何使用MongoDB聚合预测至少有2位作者,最多3位作者的书名 提前谢谢 { "_id" : 1 "subject":{ "book":[{ "bookTitle": "Design and Analysis", "author": ["L
{
"_id" : 1
"subject":{
"book":[{
"bookTitle": "Design and Analysis",
"author": ["Levitin"]
},
{
"bookTitle": "Introduction to Algorithms",
"author": ["Thomas H Cormen", "Charles E Leiserson", "Ronald L Riverst", "Clifford Stein"]
},
{
"bookTitle": "Introduction",
"author": ["James","Adam"]
},
}
}
请尝试此查询
db.collection.aggregate([
{
"$unwind": "$subject.book"
},
{
"$match": {
"subject.book.author.1": {
$exists: true
},
"subject.book.author.3": {
$exists: false
},
}
},
{
"$project": {
"subject.book.bookTitle": 1,
}
}
])