mongodb 不管存在不存在该值都会返回1?
某草草
某草草 2017-05-02 09:21:43
0
1
641

update({"tag":"9_14712612489","funding_id":9,"inventory_num":{"$gt":0}},{"$inc":{"inventory_num":-1}})

就是查找大于0的然后-1
但是这个数据不存在 也会返回true 是我程序接住了异常还是本来就是这样?

某草草
某草草

reply all(1)
过去多啦不再A梦

The main thing here is the different understanding of true and false. true means that the update operation was successful, but it does not necessarily update any records. False means that the update operation failed, which may be due to various system errors and exceptions, such as being unable to connect to mongod.

> db.user.update({"username": "test"}, {"source": "ios"})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.user.update({"username": "xxxx"}, {"source": "ios"})
WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })

Like the example above, both return true because their operations are successful, regardless of whether there is an update

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template