Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(connection+document+model): remove remaining references to remove(), clarify that deleteOne() does not execute until then() or exec() #15113

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ Connection.prototype.withSession = async function withSession(executor) {
*
* const session = await conn.startSession();
* let doc = await Person.findOne({ name: 'Ned Stark' }, null, { session });
* await doc.remove();
* await doc.deleteOne();
* // `doc` will always be null, even if reading from a replica set
* // secondary. Without causal consistency, it is possible to
* // get a doc back from the below query if the query reads from a
Expand Down
8 changes: 4 additions & 4 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2357,17 +2357,17 @@ Document.prototype.$isDefault = function(path) {
};

/**
* Getter/setter, determines whether the document was removed or not.
* Getter/setter, determines whether the document was deleted. The `Model.prototype.deleteOne()` method sets `$isDeleted` if the delete operation succeeded.
*
* #### Example:
*
* const product = await product.remove();
* const product = await product.deleteOne();
* product.$isDeleted(); // true
* product.remove(); // no-op, doesn't send anything to the db
* product.deleteOne(); // no-op, doesn't send anything to the db
*
* product.$isDeleted(false);
* product.$isDeleted(); // false
* product.remove(); // will execute a remove against the db
* product.deleteOne(); // will execute a remove against the db
*
*
* @param {Boolean} [val] optional, overrides whether mongoose thinks the doc is deleted
Expand Down
17 changes: 10 additions & 7 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,13 +694,20 @@
};

/**
* Delete this document from the db.
* Delete this document from the db. Returns a Query instance containing a `deleteOne` operation by this document's `_id`.
*
* #### Example:
*
* await product.deleteOne();
* await Product.findById(product._id); // null
*

Check failure on line 703 in lib/model.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Trailing spaces not allowed

Check failure on line 703 in lib/model.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Trailing spaces not allowed
* 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())
*
* #### Example:
*

Check failure on line 707 in lib/model.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Trailing spaces not allowed

Check failure on line 707 in lib/model.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Trailing spaces not allowed
* product.deleteOne(); // Doesn't do anything
* product.deleteOne().exec(); // Deletes the document, returns a promise
*

Check failure on line 710 in lib/model.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Trailing spaces not allowed

Check failure on line 710 in lib/model.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Trailing spaces not allowed
* @return {Query} Query
* @api public
*/
Expand Down Expand Up @@ -1879,8 +1886,6 @@
/**
* Deletes the first document that matches `conditions` from the collection.
* It returns an object with the property `deletedCount` indicating how many documents were deleted.
* Behaves like `remove()`, but deletes at most one document regardless of the
* `single` option.
*
* #### Example:
*
Expand Down Expand Up @@ -1914,8 +1919,6 @@
/**
* Deletes all of the documents that match `conditions` from the collection.
* It returns an object with the property `deletedCount` containing the number of documents deleted.
* Behaves like `remove()`, but deletes all documents that match `conditions`
* regardless of the `single` option.
*
* #### Example:
*
Expand Down Expand Up @@ -2729,7 +2732,7 @@
* // operationType: 'delete',
* // ns: { db: 'mydb', coll: 'Person' },
* // documentKey: { _id: 5a51b125c5500f5aa094c7bd } }
* await doc.remove();
* await doc.deleteOne();
*
* @param {Array} [pipeline]
* @param {Object} [options] see the [mongodb driver options](https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#watch)
Expand Down Expand Up @@ -2777,7 +2780,7 @@
*
* const session = await Person.startSession();
* let doc = await Person.findOne({ name: 'Ned Stark' }, null, { session });
* await doc.remove();
* await doc.deleteOne();
* // `doc` will always be null, even if reading from a replica set
* // secondary. Without causal consistency, it is possible to
* // get a doc back from the below query if the query reads from a
Expand Down
Loading