Skip to content

Commit 516f060

Browse files
committed
Avoid making a database query when updating a single document by _id
1 parent 40c625d commit 516f060

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/mongo/Mutator.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ export default class Mutator {
139139
...findOptions,
140140
fields: {},
141141
}).fetchAsync();
142+
} else if (Object.keys(selector).length === 1 && typeof selector._id === "string") {
143+
// if we are updating a single document by id, we can skip the find
144+
docs = [{ _id: selector._id }];
142145
} else {
143146
docs = await this.find(selector, findOptions).fetchAsync();
144147
}

0 commit comments

Comments
 (0)