Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.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
Javascript 如果只为mongo阵列的一部分提供服务,那么更新mongo阵列的正确方法是什么?_Javascript_Mongodb_Meteor - Fatal编程技术网

Javascript 如果只为mongo阵列的一部分提供服务,那么更新mongo阵列的正确方法是什么?

Javascript 如果只为mongo阵列的一部分提供服务,那么更新mongo阵列的正确方法是什么?,javascript,mongodb,meteor,Javascript,Mongodb,Meteor,我有一个集合,其中包含一系列玩家正在玩的游戏。但是,我将每个用户对该玩家游戏的查看限制为他们在我的出版物中也玩的游戏 Meteor.publish('Player.profile', function (playerId, gameId) { check(playerId, String); if (this.userId) { var games = Meteor.users.findOne(this.userId).profile().games; if(!_.co

我有一个集合,其中包含一系列玩家正在玩的
游戏。但是,我将每个用户对该玩家游戏的查看限制为他们在我的出版物中也玩的游戏


Meteor.publish('Player.profile', function (playerId, gameId) {
  check(playerId, String);
  if (this.userId) {
    var games = Meteor.users.findOne(this.userId).profile().games;
    if(!_.contains(games, gameId)) {
      return [];
    }

    return Players.find({
      _id: playerId,
      games: {
        $elemMatch: {
          _id: gameId
        }
      }
    }, {
      fields: {
        "battletag": 1,
        "games.$": 1
      }
    });
  }
  return [];
});
这将仅显示数组的单个字段


但是,当我在客户机上更新此字段时,如果知道客户机只能看到多个字段中的一个字段,如何正确地更新它?

使用?不清楚您要更新什么。您是否试图允许一个用户更新另一个用户的“游戏”字段?