I was testing the "Update if current" in mongo shell, using the documentation on the mongoDB website.
I tried to duplicate the little code snippet that was there, but the results I got back did not match. I was expecting to see the "updatedExisting" field when i called "getlasterror".
Here is exactly what i did from the mongoDB shell, along with the output.
mongos> db.t.insert(
{sku:'abc',qty:1})
mongos> db.t.find()
mongos> db.t.update({sku:"abc",qty:{$gt:0}}, { $inc :
{ qty : -1 } } )
mongos> db.$cmd.findOne(
)
{ "err" : null, "ok" : 1 }mongos> db.t.find()
{ "_id" : ObjectId("4f746863fba63782ae1d93a1"), "sku" : "abc", "qty" : 0 }mongos> db.t.update({sku:"abc",qty:{$gt:0}}, { $inc :
{ qty : -1 } } )
mongos> db.$cmd.findOne(
)
{ "err" : null, "ok" : 1 }mongos> db.t.find()
{ "_id" : ObjectId("4f746863fba63782ae1d93a1"), "sku" : "abc", "qty" : 0 }