You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Getter/setter, determines whether the document was removed or not.
2360
+
* Getter/setter, determines whether the document was deleted. The `Model.prototype.deleteOne()` method sets `$isDeleted` if the delete operation succeeded.
2361
2361
*
2362
2362
* #### Example:
2363
2363
*
2364
-
* const product = await product.remove();
2364
+
* const product = await product.deleteOne();
2365
2365
* product.$isDeleted(); // true
2366
-
* product.remove(); // no-op, doesn't send anything to the db
2366
+
* product.deleteOne(); // no-op, doesn't send anything to the db
2367
2367
*
2368
2368
* product.$isDeleted(false);
2369
2369
* product.$isDeleted(); // false
2370
-
* product.remove(); // will execute a remove against the db
2370
+
* product.deleteOne(); // will execute a remove against the db
2371
2371
*
2372
2372
*
2373
2373
* @param {Boolean} [val] optional, overrides whether mongoose thinks the doc is deleted
Copy file name to clipboardExpand all lines: lib/model.js
+10-7Lines changed: 10 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -694,13 +694,20 @@ Model.prototype.$__where = function _where(where) {
694
694
};
695
695
696
696
/**
697
-
* Delete this document from the db.
697
+
* Delete this document from the db. Returns a Query instance containing a `deleteOne` operation by this document's `_id`.
698
698
*
699
699
* #### Example:
700
700
*
701
701
* await product.deleteOne();
702
702
* await Product.findById(product._id); // null
703
703
*
704
+
* Since `deleteOne()` returns a Query, the `deleteOne()` will **not** execute unless you use either `await`, `.then()`, `.catch()`, or [`.exec()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.exec())
705
+
*
706
+
* #### Example:
707
+
*
708
+
* product.deleteOne(); // Doesn't do anything
709
+
* product.deleteOne().exec(); // Deletes the document, returns a promise
710
+
*
704
711
* @return {Query} Query
705
712
* @api public
706
713
*/
@@ -1879,8 +1886,6 @@ Model.translateAliases = function translateAliases(fields, errorOnDuplicates) {
1879
1886
/**
1880
1887
* Deletes the first document that matches `conditions` from the collection.
1881
1888
* It returns an object with the property `deletedCount` indicating how many documents were deleted.
1882
-
* Behaves like `remove()`, but deletes at most one document regardless of the
1883
-
* `single` option.
1884
1889
*
1885
1890
* #### Example:
1886
1891
*
@@ -1914,8 +1919,6 @@ Model.deleteOne = function deleteOne(conditions, options) {
1914
1919
/**
1915
1920
* Deletes all of the documents that match `conditions` from the collection.
1916
1921
* It returns an object with the property `deletedCount` containing the number of documents deleted.
1917
-
* Behaves like `remove()`, but deletes all documents that match `conditions`
0 commit comments