Mongodb returns 1 whether it exists or not?

  mongodb, question


Is to look for something greater than 0 and then -1
However, if this data does not exist, it will also return true. Did my program catch the exception or was this the way it was?

Here is mainly true and false understanding is different. True indicates that the update operation was successful, but not necessarily any records were updated. False indicates that the update operation failed, which may be various system errors and exceptions, such as not being able to connect Mongoose.

> 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 })

As in the above example, both returned true because their operations were successful, with or without updates.