我正在尝试插入子文档并一次更新集合上的一些属性,如下所示:
Collection.update(t._id, {$push: {messages: message}, text: textVar});
但这样做会收到以下消息:Exception in callback of async function: Error: Update parameter cannot have both modifier and non-modifier fields
。
有没有办法同时插入和更新?如果没有,处理这个问题的最佳方法是什么?谢谢!
答案 0 :(得分:3)
我怀疑你的第二把钥匙需要$set
:
Collection.update(t._id, {$push: {messages: message}, $set: {text: textVar}});