Skip to content

Commit

Permalink
fix(query): handle find() when buffering on initial connection
Browse files Browse the repository at this point in the history
Fix #10610
  • Loading branch information
vkarpov15 committed Aug 26, 2021
1 parent c23a76e commit 86f53ad
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,20 @@ Query.prototype._find = wrapThunk(function(callback) {

const cursor = this._collection.collection.find(filter, options);

if (typeof cursor.then === 'function' && cursor.constructor.name !== 'FindCursor') {
cursor.then(cursor => {
if (options.explain) {
return cursor.explain(cb);
}
try {
return cursor.toArray(cb);
} catch (err) {
return cb(err);
}
});
return;
}

if (options.explain) {
return cursor.explain(cb);
}
Expand Down

0 comments on commit 86f53ad

Please sign in to comment.