Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,11 @@ export function resolveOptions<T extends CommandOperationOptions>(
if (writeConcern) {
if (timeoutMS != null) {
writeConcern = WriteConcern.fromOptions({
...writeConcern,
wtimeout: undefined,
wtimeoutMS: undefined
writeConcern: {
...writeConcern,
wtimeout: undefined,
wtimeoutMS: undefined
}
});
}
result.writeConcern = writeConcern;
Expand Down
47 changes: 47 additions & 0 deletions test/integration/read-write-concern/write_concern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,51 @@ describe('Write Concern', function () {
}
});
});

describe('NODE-6763: write concern is still added with timeoutMS is set', function () {
let client: MongoClient;
let collection: Collection;
const commands: CommandStartedEvent[] = [];

beforeEach(async function () {
client = this.configuration.newClient({}, { monitorCommands: true });
client.on('commandStarted', filterForCommands('insert', commands));
collection = client.db('foo').collection('bar');
});

afterEach(async function () {
await client.close();
commands.length = 0;
});

context('when the write concern includes only timeouts', function () {
it('the writeConcern is not added to the command.', async function () {
await collection.insertOne(
{ name: 'john doe' },
{ timeoutMS: 1000, writeConcern: { wtimeout: 1000 } }
);
const [
{
command: { writeConcern }
}
] = commands;
expect(writeConcern).not.to.exist;
});
});

context('when the write concern includes only non-timeout values (`w`)', function () {
it('the writeConcern is added to the command.', async function () {
await collection.insertOne(
{ name: 'john doe' },
{ timeoutMS: 1000, writeConcern: { wtimeout: 1000, w: 'majority' } }
);
const [
{
command: { writeConcern }
}
] = commands;
expect(writeConcern).to.deep.equal({ w: 'majority' });
});
});
});
});