Home > Net >  Ok, Where is mongoose API about document.save() callback argument?
Ok, Where is mongoose API about document.save() callback argument?

Time:03-05

English is not my first language, but I'm trying hard.

The problem is that I'm using a project using Mongoose, but I can't find a description of the parameter of the callback function in document.save().

  1. genious answer
  2. Official Doc

The link gives me an accurate answer to my question, and the link's the genious who answered explains that there are three things in the callback parameter, but I can't find such an explanation anywhere in the official document, not just an option parameter, Callback parameter

But it's explained as if it's in the official document.

Am I a fool? I want to erase this pathetic question quickly. Help me, Bill Gates.

CodePudding user response:

The guide on how to execute queries mentions the following:

All callbacks in Mongoose use the pattern: callback(error, result). If an error occurs executing the query, the error parameter will contain an error document, and result will be null. If the query is successful, the error parameter will be null, and the result will be populated with the results of the query.

Since the documentation for Document.prototype.save() says nothing but:

[fn] «Function» optional callback

So you know this function is no exception to the rule. As such, doc.save((err, doc) => { }) is the signature of the callback.

  • Related