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 [];
});
这将仅显示数组的单个字段
但是,当我在客户机上更新此字段时,如果知道客户机只能看到多个字段中的一个字段,如何正确地更新它?使用?不清楚您要更新什么。您是否试图允许一个用户更新另一个用户的“游戏”字段?