Skip to content

Commit f950ae1

Browse files
Remove noResponse option
1 parent cc85ebf commit f950ae1

5 files changed

Lines changed: 27 additions & 48 deletions

File tree

src/cmap/connection.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ export interface CommandOptions extends BSONSerializeOptions {
9090
/** Session to use for the operation */
9191
session?: ClientSession;
9292
documentsReturnedIn?: string;
93-
noResponse?: boolean;
9493
omitMaxTimeMS?: boolean;
9594

9695
// TODO(NODE-2802): Currently the CommandOptions take a property willRetryWrite which is a hint
@@ -467,7 +466,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
467466
signal: options.signal
468467
});
469468

470-
if (options.noResponse || message.moreToCome) {
469+
if (message.moreToCome) {
471470
yield MongoDBResponse.empty;
472471
return;
473472
}
@@ -567,11 +566,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
567566
new CommandSucceededEvent(
568567
this,
569568
message,
570-
options.noResponse
571-
? undefined
572-
: message.moreToCome
573-
? { ok: 1 }
574-
: (object ??= document.toObject(bsonOptions)),
569+
message.moreToCome ? { ok: 1 } : (object ??= document.toObject(bsonOptions)),
575570
started,
576571
this.description.serverConnectionId
577572
)

src/operations/command.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ export interface CommandOperationOptions
5656
// Admin command overrides.
5757
dbName?: string;
5858
authdb?: string;
59-
/**
60-
* @deprecated
61-
* This option is deprecated and will be removed in an upcoming major version.
62-
*/
63-
noResponse?: boolean;
6459

6560
/**
6661
* Used when the command needs to grant access to the underlying namespaces for time series collections.

src/operations/end_sessions.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ import {
33
type Connection,
44
type ServerCommandOptions,
55
type ServerSessionId,
6-
type TimeoutContext
6+
type TimeoutContext,
7+
type WriteConcern
78
} from '..';
89
import { type Document } from '../bson';
910
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
11+
import { CommandOperation } from '../operations/command';
1012
import { ReadPreference } from '../read_preference';
1113
import { MongoDBNamespace } from '../utils';
12-
import { AbstractOperation } from './operation';
14+
import { Aspect } from './operation';
1315

14-
export class EndSessionsOperation extends AbstractOperation<void> {
16+
export class EndSessionsOperation extends CommandOperation<void> {
17+
static override aspects = new Set([Aspect.WRITE_OPERATION]);
18+
19+
override writeConcern?: WriteConcern | undefined = { w: 0 };
1520
override ns = MongoDBNamespace.fromString('admin.$cmd');
1621
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
1722

@@ -22,20 +27,17 @@ export class EndSessionsOperation extends AbstractOperation<void> {
2227
this.sessions = sessions;
2328
}
2429

25-
override buildCommand(_connection: Connection, _session?: ClientSession): Document {
30+
override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
2631
return {
2732
endSessions: this.sessions
2833
};
2934
}
30-
3135
override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
3236
return {
3337
timeoutContext,
34-
readPreference: ReadPreference.primaryPreferred,
35-
noResponse: true
38+
readPreference: ReadPreference.primaryPreferred
3639
};
3740
}
38-
3941
override get commandName(): string {
4042
return 'endSessions';
4143
}

test/integration/node-specific/mongo_client.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,23 +862,33 @@ describe('class MongoClient', function () {
862862
expect(result2).to.have.property('ok', 1);
863863
});
864864

865-
it('sends endSessions with noResponse set', async () => {
865+
it('sends endSessions with w: 0 set', async () => {
866866
const session = client.startSession(); // make a session to be ended
867867
await client.db('test').command({ ping: 1 }, { session });
868868
await session.endSession();
869869

870870
const startedEvents: CommandStartedEvent[] = [];
871-
const endEvents: Array<CommandFailedEvent | CommandSucceededEvent> = [];
871+
const endEvents: Array<CommandSucceededEvent> = [];
872872
client.on('commandStarted', event => startedEvents.push(event));
873873
client.on('commandSucceeded', event => endEvents.push(event));
874-
client.on('commandFailed', event => endEvents.push(event));
875874

876875
await client.close();
877876

878877
expect(startedEvents).to.have.lengthOf(1);
879-
expect(startedEvents[0]).to.have.property('commandName', 'endSessions');
878+
const [
879+
{
880+
command: { endSessions, writeConcern }
881+
}
882+
] = startedEvents;
883+
expect(endSessions).to.exist;
884+
expect(writeConcern).to.deep.equal({ w: 0 });
880885
expect(endEvents).to.have.lengthOf(1);
881-
expect(endEvents[0]).to.have.property('reply', undefined); // noReponse: true
886+
887+
const [{ reply }] = endEvents;
888+
889+
// when unacknowledged writes are used, the driver uses `{ ok: 1 }` as a placeholder
890+
// `reply` in CommandSucceededEvents
891+
expect(reply).to.deep.equal({ ok: 1 });
882892
});
883893

884894
describe('when server selection would return no servers', () => {

test/unit/cmap/connection.test.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,6 @@ describe('new Connection()', function () {
3535

3636
before(() => mock.createServer().then(s => (server = s)));
3737

38-
it('supports fire-and-forget messages', async function () {
39-
server.setMessageHandler(request => {
40-
const doc = request.document;
41-
if (isHello(doc)) {
42-
request.reply(mock.HELLO);
43-
}
44-
45-
// black hole all other requests
46-
});
47-
48-
const options = {
49-
...connectionOptionsDefaults,
50-
connectionType: Connection,
51-
hostAddress: server.hostAddress(),
52-
authProviders: new MongoClientAuthProviders()
53-
};
54-
55-
const conn = await connect(options);
56-
const readSpy = sinon.spy(conn, 'readMany');
57-
await conn.command(ns('$admin.cmd'), { ping: 1 }, { noResponse: true });
58-
expect(readSpy).to.not.have.been.called;
59-
});
60-
6138
it('destroys streams which time out', async function () {
6239
server.setMessageHandler(request => {
6340
const doc = request.document;

0 commit comments

Comments
 (0)