Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-6763): pass WriteConcernOptions instead on WriteConcernSettings #4421

Merged
merged 3 commits into from
Feb 18, 2025
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' });
});
});
});
});