How do you know the parameters Model.prototype.save() function takes on mongoose?

So, I know that the save function’s callback will accept at least two parameters, error, and the saved document. But when I try to check that on the docummentation, the only information I se regarding the callback is

[fn] «Function» optional callback

The question is, why is Moongose ignoring the information about the callback’s argument?

I read somewhere else that there is even third argument it can take, " The number of rows affected". How am I supposed to know about that, or if it is even true if it is not listed on the official documentation?

The purpose of these questions is to understand how to search documentation and to understand what to expect when you do that. Thanks!

Hey Mariano,

you can have a look at the types on Github.

save(options?: SaveOptions): Promise<this>;
save(options?: SaveOptions, fn?: (err: CallbackError, doc: this) => void): void;
save(fn?: (err: CallbackError, doc: this) => void): void;

So you can actually use it in 3 different ways. (an overloaded method)


This answer is from Oct 8 '15, so 6 years old.

Thanks for your reply! It is pretty clear now. I did not notice about the date, but indeed I’ll star paying attention to it!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.