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
17 changes: 16 additions & 1 deletion lib/drivers/node-mongodb-native/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function iter(i) {

let _args = args;
let callback = null;
let timeout = null;
if (this._shouldBufferCommands() && this.buffer) {
this.conn.emit('buffer', {
_id: opId,
Expand All @@ -136,7 +137,6 @@ function iter(i) {
let callback;
let _args = args;
let promise = null;
let timeout = null;
if (syncCollectionMethods[i] && typeof lastArg === 'function') {
this.addQueue(i, _args);
callback = lastArg;
Expand Down Expand Up @@ -239,6 +239,9 @@ function iter(i) {

if (syncCollectionMethods[i] && typeof lastArg === 'function') {
const result = collection[i].apply(collection, _args.slice(0, _args.length - 1));
if (timeout != null) {
clearTimeout(timeout);
}
this.conn.emit('operation-end', { _id: opId, modelName: _this.modelName, collectionName: this.name, method: i, result });
return lastArg.call(this, null, result);
}
Expand All @@ -247,6 +250,9 @@ function iter(i) {
if (ret != null && typeof ret.then === 'function') {
return ret.then(
result => {
if (timeout != null) {
clearTimeout(timeout);
}
if (typeof lastArg === 'function') {
lastArg(null, result);
} else {
Expand All @@ -255,6 +261,9 @@ function iter(i) {
return result;
},
error => {
if (timeout != null) {
clearTimeout(timeout);
}
if (typeof lastArg === 'function') {
lastArg(error);
return;
Expand All @@ -265,10 +274,16 @@ function iter(i) {
}
);
}
if (timeout != null) {
clearTimeout(timeout);
}
return ret;
} catch (error) {
// Collection operation may throw because of max bson size, catch it here
// See gh-3906
if (timeout != null) {
clearTimeout(timeout);
}
if (typeof lastArg === 'function') {
return lastArg(error);
} else {
Expand Down