Skip to content

Commit 26f15d7

Browse files
stepanhoСтепан Логвинbaileympearson
authoredFeb 18, 2025
fix(NODE-6763): pass WriteConcernOptions instead on WriteConcernSettings (#4421)
Co-authored-by: Степан Логвин <stepan.logvin@x5.ru> Co-authored-by: bailey <bailey.pearson@mongodb.com>
1 parent 94122fb commit 26f15d7

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed
 

‎src/utils.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,11 @@ export function resolveOptions<T extends CommandOperationOptions>(
531531
if (writeConcern) {
532532
if (timeoutMS != null) {
533533
writeConcern = WriteConcern.fromOptions({
534-
...writeConcern,
535-
wtimeout: undefined,
536-
wtimeoutMS: undefined
534+
writeConcern: {
535+
...writeConcern,
536+
wtimeout: undefined,
537+
wtimeoutMS: undefined
538+
}
537539
});
538540
}
539541
result.writeConcern = writeConcern;

‎test/integration/read-write-concern/write_concern.test.ts

+47
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,51 @@ describe('Write Concern', function () {
304304
}
305305
});
306306
});
307+
308+
describe('NODE-6763: write concern is still added with timeoutMS is set', function () {
309+
let client: MongoClient;
310+
let collection: Collection;
311+
const commands: CommandStartedEvent[] = [];
312+
313+
beforeEach(async function () {
314+
client = this.configuration.newClient({}, { monitorCommands: true });
315+
client.on('commandStarted', filterForCommands('insert', commands));
316+
collection = client.db('foo').collection('bar');
317+
});
318+
319+
afterEach(async function () {
320+
await client.close();
321+
commands.length = 0;
322+
});
323+
324+
context('when the write concern includes only timeouts', function () {
325+
it('the writeConcern is not added to the command.', async function () {
326+
await collection.insertOne(
327+
{ name: 'john doe' },
328+
{ timeoutMS: 1000, writeConcern: { wtimeout: 1000 } }
329+
);
330+
const [
331+
{
332+
command: { writeConcern }
333+
}
334+
] = commands;
335+
expect(writeConcern).not.to.exist;
336+
});
337+
});
338+
339+
context('when the write concern includes only non-timeout values (`w`)', function () {
340+
it('the writeConcern is added to the command.', async function () {
341+
await collection.insertOne(
342+
{ name: 'john doe' },
343+
{ timeoutMS: 1000, writeConcern: { wtimeout: 1000, w: 'majority' } }
344+
);
345+
const [
346+
{
347+
command: { writeConcern }
348+
}
349+
] = commands;
350+
expect(writeConcern).to.deep.equal({ w: 'majority' });
351+
});
352+
});
353+
});
307354
});

0 commit comments

Comments
 (0)