MongoDB的修改字段名可能无法启动以$

问题描述:

我如何使用Node.js

在server.js管理我的数据库MongoDB的使用,这个代码唤起错误

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

为什么会引发此错误,以及我如何避免此错误?

+0

在更新文档中有一个嵌套的'$ set',考虑删除外部'$ set'文件。 – chridam

问题是你重复$设置两次 而不是

{ $set: { $set: { win: 23445123123 }}} 

{ $set: { win: 23445123123 }} 

TB_LolCombinationOfChampion.update({},{ $set: { win: 23445123123 }},{multi: true},function (err, raw) { 
         if (err) console.log(err); 
         console.log('The raw response from Mongo was ', raw); 
         }); 

删除额外的$组和尝试。