【发布时间】:2017-08-03 06:37:19
【问题描述】:
我正在尝试通过推送到集合中已经存在的数组来更新集合。
这是我正在尝试运行的更新功能:
Games.update({ _id: game._id }, {
$push: { players: { name: playerName } },
});
这是我在控制台中遇到的错误:
update failed: MongoError: Cannot update 'players' and 'players' at the same time
相关架构:
Player = new SimpleSchema({
name: {
type: String,
label: 'name',
max: 50,
},
});
Schemas.Game = new SimpleSchema({
...
players: {
type: [Player],
label: 'Players',
autoValue: function () {
return [];
},
},
});
我使用autoValue 作为players 数组在创建新游戏时对其进行排序。添加第一个玩家时会出现问题吗?
我们将不胜感激。
【问题讨论】:
-
这些天我遇到了同样的问题。我设法通过使用defaultValue而不是autoValue来完成。如果你想要的只是初始化属性,那么 defautValue 就是你想要的。
标签: javascript mongodb meteor meteor-collection2