Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb:聚合嵌套文档,数组匹配_Mongodb_Aggregation Framework_Document - Fatal编程技术网

Mongodb:聚合嵌套文档,数组匹配

Mongodb:聚合嵌套文档,数组匹配,mongodb,aggregation-framework,document,Mongodb,Aggregation Framework,Document,如何使用MongoDB聚合预测至少有2位作者,最多3位作者的书名 提前谢谢 { "_id" : 1 "subject":{ "book":[{ "bookTitle": "Design and Analysis", "author": ["L

如何使用MongoDB聚合预测至少有2位作者,最多3位作者的书名

提前谢谢

{
"_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,
    }
  }
])