Skip to content

Commit

Permalink
fix(NODE-6763): pass WriteConcernOptions instead on WriteConcernSetti…
Browse files Browse the repository at this point in the history
…ngs (#4421)

Co-authored-by: Степан Логвин <stepan.logvin@x5.ru>
Co-authored-by: bailey <bailey.pearson@mongodb.com>
  • Loading branch information
3 people authored Feb 18, 2025
1 parent 94122fb commit 26f15d7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
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' });
});
});
});
});

0 comments on commit 26f15d7

Please sign in to comment.