Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interpret the lastErrorObject properties returned from MongoDB?

Tags:

mongodb

MongoDB sometimes return a lastErrorObject - and as far as I can read this is its schema:

{
  updatedExisting: <boolean>,
  upserted: <boolean>,
  n: <num>,
  connectionId: <num>,
  err: <string>,
  ok: <num>
}

But the only place on the mongodb.org website I can find any reference to this object is buried in the findAndModify API documentation.

But nowhere can I find any explanation of the different properties of the object. I can make educated guesses, but even what I can make out from the documentation seems to contradict it self. Like for instance upserted, which according to findAndModify should be a boolean, but apparently also can be an ObjectId.

And what is ok? It seems to be 1 most of the time - but it's not a boolean, so can it be 2 and what does that mean?

Even though some of the properties might be pretty self-explanatory, please write an explanation for each in your answer so it's 100% documented for everybody. Or if I just missed it (it happens), feel free to link to the documentation where this is explained ;)

like image 443
Thomas Watson Avatar asked Feb 07 '14 09:02

Thomas Watson


1 Answers

I think you have all posible return values in this page

But I agree with you. Sometimes MongoDB documentation is quite messy.

like image 108
rubenfa Avatar answered Sep 25 '22 14:09

rubenfa