Skip to content
Open
Changes from all commits
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
13 changes: 11 additions & 2 deletions lib/mongo/Mutator.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ export default class Mutator {
...findOptions,
fields: {},
}).fetchAsync();
} else if (Object.keys(selector).length === 1 && typeof selector._id === "string") {
// if we are updating a single document by id, we can skip the find
docs = [{ _id: selector._id }];
} else {
docs = await this.find(selector, findOptions).fetchAsync();
}
Expand Down Expand Up @@ -340,8 +343,14 @@ export default class Mutator {
delete removeOptions.projection;
}

// TODO: optimization check if it has _id or _id with {$in} so we don't have to redo this.
const docs = await this.find(selector, removeOptions).fetchAsync();
let docs

if (!shouldIncludePrevDocument(this) && Object.keys(selector).length === 1 && typeof selector._id === 'string') {
docs = [{ _id: selector._id }];
} else {
docs = await this.find(selector, removeOptions).fetchAsync();
}

let docIds = docs.map((doc) => doc._id);

if (!selector._id) {
Expand Down