Skip to content

Commit 39b4f37

Browse files
authored
Merge pull request #15566 from Automattic/vkarpov15/gh-15551
fix(model): remove unnecessary conversion of undefined -> null in findById
2 parents 6373d80 + b083270 commit 39b4f37

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

lib/model.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,21 +2092,14 @@ Model.find = function find(conditions, projection, options) {
20922092
};
20932093

20942094
/**
2095-
* Finds a single document by its _id field. `findById(id)` is almost*
2096-
* equivalent to `findOne({ _id: id })`. If you want to query by a document's
2097-
* `_id`, use `findById()` instead of `findOne()`.
2095+
* Finds a single document by its _id field. `findById(id)` is equivalent to `findOne({ _id: id })`.
20982096
*
20992097
* The `id` is cast based on the Schema before sending the command.
21002098
*
21012099
* This function triggers the following middleware.
21022100
*
21032101
* - `findOne()`
21042102
*
2105-
* \* Except for how it treats `undefined`. If you use `findOne()`, you'll see
2106-
* that `findOne(undefined)` and `findOne({ _id: undefined })` are equivalent
2107-
* to `findOne({})` and return arbitrary documents. However, mongoose
2108-
* translates `findById(undefined)` into `findOne({ _id: null })`.
2109-
*
21102103
* #### Example:
21112104
*
21122105
* // Find the adventure with the given `id`, or `null` if not found
@@ -2131,10 +2124,6 @@ Model.findById = function findById(id, projection, options) {
21312124
throw new MongooseError('Model.findById() no longer accepts a callback');
21322125
}
21332126

2134-
if (typeof id === 'undefined') {
2135-
id = null;
2136-
}
2137-
21382127
return this.findOne({ _id: id }, projection, options);
21392128
};
21402129

0 commit comments

Comments
 (0)