By default, you can get two parameters in the callback function: err and results . The first contains all errors that occurred at run time, and the second contains the old value of the document. However, you can get other variables in the callback parameters if you set some parameters in the findOneAndUpdate method. Let's look at this with an example:
Model.findOneAndUpdate( { id: id_var }, { $set: { name: name_var } }, {new: true, passRawResult: true}, (err, doc, raw) => { })
In this case, the new: true parameter indicates that the doc variable contains the new updated object. The passRawResult: true option indicates that you can get the original MongoDB driver result as the third callback parameter. The raw parameter contains the update result, something like this:
"raw": { "lastErrorObject": { "updatedExisting": true, "n": 1 }, "value": { }, "ok": 1, "_kareemIgnore": true }
source share