【问题描述】
集合结构如下:
db.exec("select * from foo.bar where nm = 'name39'")
{
"_id": {
"$oid": "575e4f9fbdf14a8f7c00002a"
},
"age": 18,
"nm": "name39",
"no": 39
}
对集合foo.bar的no字段做set no=no+2操作报错
db.execUpdate("update foo.bar set no=no+2 where nm = 'name39'")
(nofile):0 uncaught exception: -195
SQL syntax error
Takes 0.1040s.
【解决办法】
目前内置sql还不支持该操作,可以使用下面这种模式代替
db.foo.bar.update({nm:"name39"},{$inc:{no:2}})
【参考链接】
错误码
常见错误处理指南