0

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.

coolhong
  • 65
  • 6

1 Answers1

1

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.

RickN
  • 12,537
  • 4
  • 24
  • 28
  • Thank you so much. That's the answer I wanted. As a junior, I'd like to ask you one question. Do you read all the official documents from the beginning? Am I supposed to study like that? I never thought this would be included in the query category. – coolhong Mar 04 '22 at 15:27
  • Mongoose's documentation isn't that long, so reading the guides from "Schemas" through "Populate" is very do-able and informative. Some subjects, such as Discriminators are a bit advanced, you could peek at it, but there's no need to know all documentation by heart—if you give it a quick glance, you'll know _what exists and what's possible_ so you can later look it up when you actually need it. – RickN Mar 07 '22 at 09:03