multi update only works with $ operators

数据库执行没问题,test.sh中执行报错

WriteResult({
	"nMatched" : 0,
	"nUpserted" : 0,
	"nModified" : 0,
	"writeError" : {
		"code" : 9,
		"errmsg" : "multi update only works with $ operators"
	}
})

语句

db.user.update({"failsCount" : {"$gte":1}},{"$set":{"failsCount": 0,"active":true}},false,true)
db.user.update({"failsCount" : {"$gte":1}},{"$set":{"failsCount": 0,"active":true}},{multi:true})

需改为

db.user.update({"failsCount" : {"\$gte":10}},{"\$set":{"failsCount": 0,"active":true}},false,true)

完整如下

#!/bin/sh
echo "[`date '+%Y-%m-%d %H:%M:%S'`]start............................................."  >> /home/log/unlock.log
mongo 127.0.0.1:27017<data;
db.auth("xxx","xxx");
db.user.update({"failsCount" : {"\$gte":10}},{"\$set":{"failsCount": 0,"active":true}},false,true)
exit;
echo "[`date '+%Y%m%d%H%M%S'`] end............................................."  >> /home/log/unlock.log

你可能感兴趣的:(mongodb,shell)