Skip to content

Commit

Permalink
fix: keep autoIndex & autoCreate as true by default if read preferenc…
Browse files Browse the repository at this point in the history
…e is primaryPreferred

Fix #11976
Re: #9941
  • Loading branch information
vkarpov15 committed Jul 1, 2022
1 parent 9ba3f12 commit 2eb9314
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/helpers/processConnectionOptions.js
Expand Up @@ -9,7 +9,7 @@ function processConnectionOptions(uri, options) {
? opts.readPreference
: getUriReadPreference(uri);

const resolvedOpts = (readPreference && readPreference !== 'primary')
const resolvedOpts = (readPreference && readPreference !== 'primary' && readPreference !== 'primaryPreferred')
? resolveOptsConflicts(readPreference, opts)
: opts;

Expand Down
7 changes: 7 additions & 0 deletions test/connection.test.js
Expand Up @@ -1074,6 +1074,13 @@ describe('connections:', function() {
assert.equal(conn2.get('autoCreate'), false);
});

it('keeps autoIndex & autoCreate as true by default if read preference is primaryPreferred (gh-9374)', function() {
const conn = new mongoose.createConnection(start.uri, { readPreference: 'primaryPreferred' });

assert.equal(conn.get('autoIndex'), undefined);
assert.equal(conn.get('autoCreate'), undefined);
});

it('throws if options try to set autoIndex to true', function() {
const opts = {
readPreference: 'secondary',
Expand Down

0 comments on commit 2eb9314

Please sign in to comment.