Model.prototype.remove()

Parameters
  • [options] «Object»

  • [options.session=null] «Session» the session associated with this operation. If not specified, defaults to the document’s associated session.

  • [fn] «function(err|product)» optional callback

Returns:
  • «Promise» Promise

Removes this document from the db.

Example:

  1. product.remove(function (err, product) {
  2. if (err) return handleError(err);
  3. Product.findById(product._id, function (err, product) {
  4. console.log(product) // null
  5. })
  6. })

As an extra measure of flow control, remove will return a Promise (bound to fn if passed) so it could be chained, or hooked to recieve errors

Example:

  1. product.remove().then(function (product) {
  2. ...
  3. }).catch(function (err) {
  4. assert.ok(err)
  5. })