在我的数组中查找特定元素的所有数据

Find all data for a specific element in my array

我是 MongoDB 的新手。我已经将 json 文件导入到我的 MongoDB 中。结构如下所示:

我想做的是获取玩家 0、玩家 1 等的所有数据,但我不知道我的 db.collection.find 应该是什么样子。

使用db.collection.aggregate([{$unwind:"$match.players"}])。您还可以选择要投影的字段和不投影的字段。您可以将其添加到聚合管道中。

     db.collection.aggregate([{$unwind:"$match.players"},
                               {$project:{_id:1, player:'$match.players'}}
                             ]);