Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ export const OPTIONS = {
type: 'uint'
},
monitorCommands: {
default: true,
default: false,
type: 'boolean'
},
name: {
Expand Down
66 changes: 66 additions & 0 deletions test/unit/mongo_client_options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const os = require('os');
const fs = require('fs');
const { expect } = require('chai');
const { getSymbolFrom } = require('../tools/utils');
const { parseOptions } = require('../../src/connection_string');
const { ReadConcern } = require('../../src/read_concern');
const { WriteConcern } = require('../../src/write_concern');
Expand Down Expand Up @@ -450,4 +451,69 @@ describe('MongoOptions', function () {
);
});
});

describe('default options', () => {
const doNotCheckEq = Symbol('do not check equality');
const KNOWN_DEFAULTS = [
['connecttimeoutms', 30000],
['directconnection', false],
['forceserverobjectid', false],
['heartbeatfrequencyms', 10000],
['keepalive', true],
['keepaliveinitialdelay', 120000],
['localthresholdms', 15],
['logger', doNotCheckEq],
['maxidletimems', 0],
['maxpoolsize', 100],
['minpoolsize', 0],
['minheartbeatfrequencyms', 500],
['monitorcommands', false], // NODE-3513
['nodelay', true],
['raw', false],
['retryreads', true],
['retrywrites', true],
['serverselectiontimeoutms', 30000],
['sockettimeoutms', 0],
['waitqueuetimeoutms', 0],
['zlibcompressionlevel', 0],

// map to objects that are not worth checking deep equality
['compressors', doNotCheckEq],
['readpreference', doNotCheckEq],
['pkfactory', doNotCheckEq]
];

const findMatchingKey = (o, searchKey) => {
return Object.keys(o).filter(key => {
return key.toLowerCase() === searchKey;
})[0];
};

it(`should define known defaults in client.options`, () => {
const client = new MongoClient('mongodb://localhost');
const clientOptions = client.options;

for (const [optionName, value] of KNOWN_DEFAULTS) {
const camelCaseName = findMatchingKey(clientOptions, optionName);
expect(camelCaseName, `did not find a camelcase match for ${optionName}`).to.be.a('string');

expect(clientOptions).to.have.property(camelCaseName);

if (value !== doNotCheckEq) {
expect(clientOptions).to.have.property(camelCaseName).that.deep.equals(value);
}
}
});

it('set monitorCommands to false (NODE-3513)', function () {
const client = new MongoClient('mongodb://localhost');
const clientOptions = client.options;

expect(clientOptions).to.have.property('monitorCommands', false);
expect(client.s.options).to.have.property('monitorCommands', false);
expect(client).to.have.property('monitorCommands', false);
const optionsSym = getSymbolFrom(client, 'options');
expect(client[optionsSym]).to.have.property('monitorCommands', false);
});
});
});