Document.prototype.save()

Parameters
Returns:
  • «Promise,undefined» Returns undefined if used with callback or a Promise otherwise.

Saves this document by inserting a new document into the database if document.isNew is true, or sends an updateOne operation only with the modifications to the database, it does not replace the whole document in the latter case.

Example:

  1. product.sold = Date.now();
  2. product = await product.save();

If save is successful, the returned promise will fulfill with the document saved.

Example:

  1. const newProduct = await product.save();
  2. newProduct === product; // true