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

Mongodb 查找数组中特定元素的所有数据,mongodb,robo3t,Mongodb,Robo3t,我是MongoDB的新手。我已经将一个json文件导入到我的MongoDB中。结构如下所示: 我想做的是获取玩家0,玩家1的所有数据,。。等等,但我不知道我的db.collection.find应该是什么样子。使用db.collection.aggregate([{$unwind:$match.players}])。您还可以选择要投影的字段和不投影的字段。您可以将其添加到聚合管道中 db.collection.aggregate([{$unwind:"$match.players"}

我是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'}}
                             ]);

你真正想要实现什么?您的查询应该返回什么?它应该返回播放器[0]块可能的重复使用
$unwind
聚合
框架。如果您可以提供一个示例数据集,我可能会尝试编写精确的查询。这是我的json文件: