Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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_Meteor - Fatal编程技术网

Mongodb 如何在基于数组值的集合中查找文档

Mongodb 如何在基于数组值的集合中查找文档,mongodb,meteor,Mongodb,Meteor,我尝试添加一个帮助器以返回包含文档的数组,如下所示: documents = { realPlayers: [], subscribers: [ {playerId: }, {playerId: }, {playerId: } ], privatGame:, gameType:, gameStatus: 'active' } 我试过这个,但不起作

我尝试添加一个帮助器以返回包含文档的数组,如下所示:

documents = {
  realPlayers: [],
  subscribers: [
                {playerId: }, 
                {playerId: }, 
                {playerId: }
               ],
  privatGame:,
  gameType:,
  gameStatus: 'active'
}
我试过这个,但不起作用(forEach也一样):

Template.myGames.helpers({
“myGames”:函数(){
设gamePul=[],
activeGames=Games.find({gameStatus:“active”});
for(var i=0;i
您只是想找到当前用户订阅的游戏集,对吗?您只需在查询中使用
$elemMatch

Template.myGames.helpers({
  myGames: function() {
    return Games.find({ gameStatus: "active",
      subscribers: { $elemMatch: { playerId: Meteor.userId() }}});
  }
});

你从
activeGames
中得到了什么回报?应该是一个光标,您可以在上使用
.forEach
。你有什么结果吗?是的,你完全正确,它完全起作用了!谢谢
Template.myGames.helpers({
  myGames: function() {
    return Games.find({ gameStatus: "active",
      subscribers: { $elemMatch: { playerId: Meteor.userId() }}});
  }
});