Skip to content

Commit

Permalink
fix(find): correctly translate timeout option into noCursorTimeout (#…
Browse files Browse the repository at this point in the history
…2700)

The find command's `timeout` option was incorrectly being translated
into `noCursorTimeout`, this has been corrected to be `!timeout`.

NODE-2828
  • Loading branch information
emadum committed Jan 19, 2021
1 parent 60936dc commit e257e6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/collection.js
Expand Up @@ -429,7 +429,7 @@ Collection.prototype.find = deprecateOptions(
}

// Translate to new command option noCursorTimeout
if (typeof newOptions.timeout === 'boolean') newOptions.noCursorTimeout = newOptions.timeout;
if (typeof newOptions.timeout === 'boolean') newOptions.noCursorTimeout = !newOptions.timeout;

decorateCommand(findCommand, newOptions, ['session', 'collation']);

Expand Down
16 changes: 10 additions & 6 deletions test/functional/find.test.js
Expand Up @@ -1195,19 +1195,23 @@ describe('Find', function() {

// The actual test we wish to run
test: function(done) {
var configuration = this.configuration;
var client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });
const configuration = this.configuration;
const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });
client.connect(function(err, client) {
var db = client.db(configuration.db);
const db = client.db(configuration.db);
db.createCollection('timeoutFalse', function(err, collection) {
expect(err).to.not.exist;
collection.find({}, { timeout: false }, function(err, cursor) {
test.equal(false, cursor.cmd.noCursorTimeout);
expect(err).to.not.exist;
expect(cursor.cmd.noCursorTimeout).to.be.true;

collection.find({}, { timeout: true }, function(err, cursor) {
test.equal(true, cursor.cmd.noCursorTimeout);
expect(err).to.not.exist;
expect(cursor.cmd.noCursorTimeout).to.be.false;

collection.find({}, {}, function(err, cursor) {
test.ok(!cursor.cmd.noCursorTimeout);
expect(err).to.not.exist;
expect(cursor.cmd.noCursorTimeout).to.not.exist;

client.close(done);
});
Expand Down

0 comments on commit e257e6b

Please sign in to comment.