Skip to content

Commit

Permalink
fix(NODE-6377): Remove noResponse option
Browse files Browse the repository at this point in the history
  • Loading branch information
aditi-khare-mongoDB committed Sep 16, 2024
1 parent 6104c57 commit 89ed6a3
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 18 deletions.
9 changes: 2 additions & 7 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export interface CommandOptions extends BSONSerializeOptions {
/** Session to use for the operation */
session?: ClientSession;
documentsReturnedIn?: string;
noResponse?: boolean;
omitReadPreference?: boolean;

// TODO(NODE-2802): Currently the CommandOptions take a property willRetryWrite which is a hint
Expand Down Expand Up @@ -439,7 +438,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
zlibCompressionLevel: this.description.zlibCompressionLevel
});

if (options.noResponse || message.moreToCome) {
if (message.moreToCome) {
yield MongoDBResponse.empty;
return;
}
Expand Down Expand Up @@ -527,11 +526,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
new CommandSucceededEvent(
this,
message,
options.noResponse
? undefined
: message.moreToCome
? { ok: 1 }
: (object ??= document.toObject(bsonOptions)),
message.moreToCome ? { ok: 1 } : (object ??= document.toObject(bsonOptions)),
started,
this.description.serverConnectionId
)
Expand Down
2 changes: 1 addition & 1 deletion src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
this,
new RunAdminCommandOperation(
{ endSessions },
{ readPreference: ReadPreference.primaryPreferred, noResponse: true }
{ readPreference: ReadPreference.primaryPreferred, writeConcern: { w: 0 } }
)
);
} catch (error) {
Expand Down
1 change: 0 additions & 1 deletion src/operations/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export interface CommandOperationOptions
// Admin command overrides.
dbName?: string;
authdb?: string;
noResponse?: boolean;
}

/** @internal */
Expand Down
9 changes: 7 additions & 2 deletions src/operations/run_command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { type TODO_NODE_3286 } from '../mongo_types';
import type { ReadPreferenceLike } from '../read_preference';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import type { WriteConcern } from '../write_concern';
import { MongoDBNamespace } from '../utils';
import { AbstractOperation } from './operation';
import { Aspect, defineAspects, AbstractOperation } from './operation';

/** @public */
export type RunCommandOptions = {
Expand Down Expand Up @@ -51,7 +52,7 @@ export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T>
constructor(
public command: Document,
public override options: RunCommandOptions & {
noResponse?: boolean;
writeConcern?: WriteConcern;
bypassPinningCheck?: boolean;
}
) {
Expand All @@ -73,3 +74,7 @@ export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T>
return res;
}
}

defineAspects(RunAdminCommandOperation, [
Aspect.WRITE_OPERATION
]);
4 changes: 2 additions & 2 deletions test/integration/collection-management/collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,15 @@ describe('Collection', function () {
}
}

it('isCapped should return false for uncapped collections', async function () {
it.only('isCapped should return false for uncapped collections', async function () {
await testCapped(configuration, {
config: configuration,
collName: 'uncapped',
opts: { capped: false }
});
});

it('isCapped should return false for collections instantiated without specifying capped', async function () {
it.only('isCapped should return false for collections instantiated without specifying capped', async function () {
await testCapped(configuration, { config: configuration, collName: 'uncapped2', opts: {} });
});

Expand Down
2 changes: 1 addition & 1 deletion test/integration/crud/misc_cursors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ describe('Cursor', function () {
}
});

it('does not auto destroy streams', function (done) {
it.only('does not auto destroy streams', function (done) {
const docs = [];

for (var i = 0; i < 10; i++) {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/node-specific/mongo_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ describe('class MongoClient', function () {
expect(result2).to.have.property('ok', 1);
});

it('sends endSessions with noResponse set', async () => {
it('sends endSessions with writeConcern w = 0 set', async () => {
const session = client.startSession(); // make a session to be ended
await client.db('test').command({ ping: 1 }, { session });
await session.endSession();
Expand All @@ -698,7 +698,7 @@ describe('class MongoClient', function () {
expect(startedEvents).to.have.lengthOf(1);
expect(startedEvents[0]).to.have.property('commandName', 'endSessions');
expect(endEvents).to.have.lengthOf(1);
expect(endEvents[0]).to.have.property('reply', undefined); // noReponse: true
expect(endEvents[0]).to.containSubset({ reply: { ok: 1 } }); // writeConcern.w = 0
});

context('when server selection would return no servers', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/read-write-concern/write_concern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import * as mock from '../../tools/mongodb-mock/index';
import { filterForCommands } from '../shared';

describe('Write Concern', function () {
describe.only('Write Concern', function () {
context('when the WriteConcern is set in the uri', function () {
let client;
const events: CommandStartedEvent[] = [];
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cmap/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('new Connection()', function () {

const conn = await connect(options);
const readSpy = sinon.spy(conn, 'readMany');
await conn.command(ns('$admin.cmd'), { ping: 1 }, { noResponse: true });
await conn.command(ns('$admin.cmd'), { ping: 1 }, { writeConcern: { w: 0 } });
expect(readSpy).to.not.have.been.called;
});

Expand Down

0 comments on commit 89ed6a3

Please sign in to comment.