mafintosh/mongojs — pull request #125 by watson (2014-03-03 19:37:24+00:00)
Title: Extract lastErrorObject from the err argument if findAndModify fails

If `findAndModify` experiences an error, the `obj` argument to the callback is `undefined`. Instead the `lastErrorObject` is attached to the `err` argument, from where we extract it.

To not rely on the `lastErrorObject` **always** being on the `err` object if provided, we gracefully fall back to looking in the `obj` object and then finally just return `{ n: 0 }` if no `lastErrorObject` is found. This could be a more strict algorithm, but this seems more future-proof.