我使用 node.js 通过 mongodb 管理我的数据库
在 server.js 中,此代码引发错误
TB_LolCombinationOfChampion.update({},{ $set: { $set: { win: 23445123123 }}},{multi: true},function (err, raw) {
if (err) console.log(err);
console.log('The raw response from Mongo was ', raw);
});
我收到此错误
{ [MongoError: Modified field name may not start with $]
name: 'MongoError',
err: 'Modified field name may not start with $',
code: 15896,
n: 0,
connectionId: 601,
ok: 1 }
The raw response from Mongo was null
为什么会引发此错误以及如何避免此错误?
最佳答案
问题是你重复了 $set 两次 而不是
{ $set: { $set: { win: 23445123123 }}}
做
{ $set: { win: 23445123123 }}
关于node.js - mongodb 修改字段名不能以$开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37788647/