Model.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 with just the modified paths if isNew is false.

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