Skip to content

Commit b7d94c5

Browse files
committed
Optimize remove
1 parent 516f060 commit b7d94c5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/mongo/Mutator.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,14 @@ export default class Mutator {
343343
delete removeOptions.projection;
344344
}
345345

346-
// TODO: optimization check if it has _id or _id with {$in} so we don't have to redo this.
347-
const docs = await this.find(selector, removeOptions).fetchAsync();
346+
let docs
347+
348+
if (Object.keys(selector).length === 1 && typeof selector._id === "string") {
349+
docs = [{ _id: selector._id }];
350+
} else {
351+
docs = await this.find(selector, removeOptions).fetchAsync();
352+
}
353+
348354
let docIds = docs.map((doc) => doc._id);
349355

350356
if (!selector._id) {

0 commit comments

Comments
 (0)