Skip to content

Commit

Permalink
docs: remove confusing references to executing a query immediately
Browse files Browse the repository at this point in the history
Fix #7461
  • Loading branch information
vkarpov15 committed Feb 4, 2019
1 parent bc95a22 commit 704a5a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
6 changes: 3 additions & 3 deletions docs/queries.jade
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ block content
- [`Model.updateOne()`](/docs/api.html#model_Model.updateOne)

A mongoose query can be executed in one of two ways. First, if you
pass in a `callback` function the operation will be executed immediately
with the results passed to the callback.
pass in a `callback` function, Mongoose will execute the query asynchronously
and pass the results to the `callback`.

A query also has a `.then()` function, and thus can be used as a promise.

Expand Down Expand Up @@ -68,7 +68,7 @@ block content
});
```

Here we see that the query was executed immediately and the results passed to our callback. All callbacks in Mongoose use the pattern:
Mongoose executed the query and passed the results passed to `callback`. All callbacks in Mongoose use the pattern:
`callback(error, result)`. If an error occurs executing the query, the `error` parameter will contain an error document, and `result`
will be null. If the query is successful, the `error` parameter will be null, and the `result` will be populated with the results of the query.

Expand Down
23 changes: 11 additions & 12 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1742,16 +1742,16 @@ Model.deleteMany = function deleteMany(conditions, options, callback) {
* // named john and at least 18
* MyModel.find({ name: 'john', age: { $gte: 18 }});
*
* // executes immediately, passing results to callback
* // executes, passing results to callback
* MyModel.find({ name: 'john', age: { $gte: 18 }}, function (err, docs) {});
*
* // name LIKE john and only selecting the "name" and "friends" fields, executing immediately
* // executes, name LIKE john and only selecting the "name" and "friends" fields
* MyModel.find({ name: /john/i }, 'name friends', function (err, docs) { })
*
* // passing options
* MyModel.find({ name: /john/i }, null, { skip: 10 })
*
* // passing options and executing immediately
* // passing options and executes
* MyModel.find({ name: /john/i }, null, { skip: 10 }, function (err, docs) {});
*
* // executing a query explicitly
Expand Down Expand Up @@ -1824,7 +1824,7 @@ Model.find = function find(conditions, projection, options, callback) {
*
* ####Example:
*
* // find adventure by id and execute immediately
* // find adventure by id and execute
* Adventure.findById(id, function (err, adventure) {});
*
* // same as above
Expand Down Expand Up @@ -2050,7 +2050,7 @@ Model.count = function count(conditions, callback) {
/**
* Creates a Query for a `distinct` operation.
*
* Passing a `callback` immediately executes the query.
* Passing a `callback` executes the query.
*
* ####Example
*
Expand Down Expand Up @@ -2140,7 +2140,7 @@ Model.$where = function $where() {
/**
* Issues a mongodb findAndModify update command.
*
* Finds a matching document, updates it according to the `update` arg, passing any `options`, and returns the found document (if any) to the callback. The query executes immediately if `callback` is passed else a Query object is returned.
* Finds a matching document, updates it according to the `update` arg, passing any `options`, and returns the found document (if any) to the callback. The query executes if `callback` is passed else a Query object is returned.
*
* ####Options:
*
Expand Down Expand Up @@ -2273,8 +2273,7 @@ function _decorateUpdateWithVersionKey(update, options, versionKey) {
*
* Finds a matching document, updates it according to the `update` arg,
* passing any `options`, and returns the found document (if any) to the
* callback. The query executes immediately if `callback` is passed else a
* Query object is returned.
* callback. The query executes if `callback` is passed.
*
* This function triggers the following middleware.
*
Expand Down Expand Up @@ -2372,7 +2371,7 @@ Model.findByIdAndUpdate = function(id, update, options, callback) {
* Finds a matching document, removes it, and passes the found document
* (if any) to the callback.
*
* Executes immediately if `callback` is passed else a Query object is returned.
* Executes the query if `callback` is passed.
*
* This function triggers the following middleware.
*
Expand Down Expand Up @@ -2493,7 +2492,7 @@ Model.findByIdAndDelete = function(id, options, callback) {
* Finds a matching document, replaces it with the provided doc, and passes the
* returned doc to the callback.
*
* Executes immediately if `callback` is passed else a Query object is returned.
* Executes the query if `callback` is passed.
*
* This function triggers the following query middleware.
*
Expand Down Expand Up @@ -2562,7 +2561,7 @@ Model.findOneAndReplace = function(conditions, options, callback) {
*
* Finds a matching document, removes it, passing the found document (if any) to the callback.
*
* Executes immediately if `callback` is passed else a Query object is returned.
* Executes the query if `callback` is passed.
*
* This function triggers the following middleware.
*
Expand Down Expand Up @@ -2645,7 +2644,7 @@ Model.findOneAndRemove = function(conditions, options, callback) {
*
* Finds a matching document, removes it, passing the found document (if any) to the callback.
*
* Executes immediately if `callback` is passed, else a `Query` object is returned.
* Executes the query if `callback` is passed.
*
* This function triggers the following middleware.
*
Expand Down
13 changes: 9 additions & 4 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -2702,7 +2702,9 @@ function prepareDiscriminatorCriteria(query) {
/**
* Issues a mongodb [findAndModify](http://www.mongodb.org/display/DOCS/findAndModify+Command) update command.
*
* Finds a matching document, updates it according to the `update` arg, passing any `options`, and returns the found document (if any) to the callback. The query executes immediately if `callback` is passed.
* Finds a matching document, updates it according to the `update` arg, passing any `options`, and returns the found
* document (if any) to the callback. The query executes if
* `callback` is passed.
*
* This function triggers the following middleware.
*
Expand Down Expand Up @@ -2833,7 +2835,8 @@ Query.prototype._findOneAndUpdate = wrapThunk(function(callback) {
/**
* Issues a mongodb [findAndModify](http://www.mongodb.org/display/DOCS/findAndModify+Command) remove command.
*
* Finds a matching document, removes it, passing the found document (if any) to the callback. Executes immediately if `callback` is passed.
* Finds a matching document, removes it, passing the found document (if any) to
* the callback. Executes if `callback` is passed.
*
* This function triggers the following middleware.
*
Expand Down Expand Up @@ -2911,7 +2914,8 @@ Query.prototype.findOneAndRemove = function(conditions, options, callback) {
/**
* Issues a MongoDB [findOneAndDelete](https://docs.mongodb.com/manual/reference/method/db.collection.findOneAndDelete/) command.
*
* Finds a matching document, removes it, and passes the found document (if any) to the callback. Executes immediately if `callback` is passed.
* Finds a matching document, removes it, and passes the found document (if any)
* to the callback. Executes if `callback` is passed.
*
* This function triggers the following middleware.
*
Expand Down Expand Up @@ -3033,7 +3037,8 @@ Query.prototype._findOneAndDelete = wrapThunk(function(callback) {
/**
* Issues a MongoDB [findOneAndReplace](https://docs.mongodb.com/manual/reference/method/db.collection.findOneAndReplace/) command.
*
* Finds a matching document, removes it, and passes the found document (if any) to the callback. Executes immediately if `callback` is passed.
* Finds a matching document, removes it, and passes the found document (if any)
* to the callback. Executes if `callback` is passed.
*
* This function triggers the following middleware.
*
Expand Down

0 comments on commit 704a5a4

Please sign in to comment.