Skip to content Skip to sidebar Skip to footer

How Does Mongoose's Save Callback Work?

For the MEAN stack, I'm learning about Mongoose's save() function, which takes a callback. Its API states: Model#save([options], [fn]) Saves this document. Parameters: [options]

Solution 1:

The save function's callback will accept three arguments :

  • The error
  • The document that was saved
  • The number of rows affected

The arguments are listed here

Note that the second argument, the document, must be the same document that is calling the save

You can name the arguments however you want, you're not casting it to an object or anything like that. It's simply a name that you want to use to refer it to in your function's body.

Post a Comment for "How Does Mongoose's Save Callback Work?"