Skip to content

Commit 3b2a138

Browse files
committed
fix(query): avoid double-calling query transform() with findOne()
Fix #14236
1 parent ad5f8a1 commit 3b2a138

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

lib/query.js

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,12 +2498,12 @@ Query.prototype._findOne = async function _findOne() {
24982498
// don't pass in the conditions because we already merged them in
24992499
const doc = await this.mongooseCollection.findOne(this._conditions, options);
25002500
return new Promise((resolve, reject) => {
2501-
this._completeOne(doc, null, _wrapThunkCallback(this, (err, res) => {
2501+
this._completeOne(doc, null, (err, res) => {
25022502
if (err) {
25032503
return reject(err);
25042504
}
25052505
resolve(res);
2506-
}));
2506+
});
25072507
});
25082508
};
25092509

@@ -3303,12 +3303,12 @@ Query.prototype._findOneAndUpdate = async function _findOneAndUpdate() {
33033303
const doc = !options.includeResultMetadata ? res : res.value;
33043304

33053305
return new Promise((resolve, reject) => {
3306-
this._completeOne(doc, res, _wrapThunkCallback(this, (err, res) => {
3306+
this._completeOne(doc, res, (err, res) => {
33073307
if (err) {
33083308
return reject(err);
33093309
}
33103310
resolve(res);
3311-
}));
3311+
});
33123312
});
33133313
};
33143314

@@ -3399,12 +3399,12 @@ Query.prototype._findOneAndDelete = async function _findOneAndDelete() {
33993399
const doc = !includeResultMetadata ? res : res.value;
34003400

34013401
return new Promise((resolve, reject) => {
3402-
this._completeOne(doc, res, _wrapThunkCallback(this, (err, res) => {
3402+
this._completeOne(doc, res, (err, res) => {
34033403
if (err) {
34043404
return reject(err);
34053405
}
34063406
resolve(res);
3407-
}));
3407+
});
34083408
});
34093409
};
34103410

@@ -3553,12 +3553,12 @@ Query.prototype._findOneAndReplace = async function _findOneAndReplace() {
35533553

35543554
const doc = !includeResultMetadata ? res : res.value;
35553555
return new Promise((resolve, reject) => {
3556-
this._completeOne(doc, res, _wrapThunkCallback(this, (err, res) => {
3556+
this._completeOne(doc, res, (err, res) => {
35573557
if (err) {
35583558
return reject(err);
35593559
}
35603560
resolve(res);
3561-
}));
3561+
});
35623562
});
35633563
};
35643564

@@ -4382,28 +4382,6 @@ function _executePreHooks(query, op) {
43824382
});
43834383
}
43844384

4385-
/*!
4386-
* ignore
4387-
*/
4388-
4389-
function _wrapThunkCallback(query, cb) {
4390-
return function(error, res) {
4391-
if (error != null) {
4392-
return cb(error);
4393-
}
4394-
4395-
for (const fn of query._transforms) {
4396-
try {
4397-
res = fn(res);
4398-
} catch (error) {
4399-
return cb(error);
4400-
}
4401-
}
4402-
4403-
return cb(null, res);
4404-
};
4405-
}
4406-
44074385
/**
44084386
* Executes the query returning a `Promise` which will be
44094387
* resolved with either the doc(s) or rejected with the error.

0 commit comments

Comments
 (0)