Skip to content

Commit

Permalink
fix(NODE-3511): deprecate fullResponse and remove associated buggy co…
Browse files Browse the repository at this point in the history
…de paths (#2943)
  • Loading branch information
dariakp committed Aug 23, 2021
1 parent 8fc9ae1 commit dfc39d1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
16 changes: 9 additions & 7 deletions src/cmap/connection.ts
Expand Up @@ -63,6 +63,8 @@ const kDescription = Symbol('description');
const kIsMaster = Symbol('ismaster');
/** @internal */
const kAutoEncrypter = Symbol('autoEncrypter');
/** @internal */
const kFullResult = Symbol('fullResult');

/** @internal */
export interface QueryOptions extends BSONSerializeOptions {
Expand All @@ -81,15 +83,15 @@ export interface QueryOptions extends BSONSerializeOptions {
oplogReplay?: boolean;
}

/** @public */
/** @internal */
export interface CommandOptions extends BSONSerializeOptions {
command?: boolean;
slaveOk?: boolean;
/** Specify read preference if command supports it */
readPreference?: ReadPreferenceLike;
raw?: boolean;
monitoring?: boolean;
fullResult?: boolean;
[kFullResult]?: boolean;
socketTimeoutMS?: number;
/** Session to use for the operation */
session?: ClientSession;
Expand Down Expand Up @@ -492,7 +494,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
write(
this,
query,
{ fullResult: true, ...pluckBSONSerializeOptions(options) },
{ [kFullResult]: true, ...pluckBSONSerializeOptions(options) },
(err, result) => {
if (err || !result) return callback(err, result);
if (isExplain && result.documents && result.documents[0]) {
Expand All @@ -511,7 +513,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
options: GetMoreOptions,
callback: Callback<Document>
): void {
const fullResult = typeof options.fullResult === 'boolean' ? options.fullResult : false;
const fullResult = !!options[kFullResult];
const wireVersion = maxWireVersion(this);
if (!cursorId) {
// TODO(NODE-3483): Replace this with a MongoCommandError
Expand All @@ -526,7 +528,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
Object.assign(options, { ...pluckBSONSerializeOptions(options) })
);

queryOptions.fullResult = true;
queryOptions[kFullResult] = true;
queryOptions.command = true;
write(this, getMoreOp, queryOptions, (err, response) => {
if (fullResult) return callback(err, response);
Expand Down Expand Up @@ -591,7 +593,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
this.command(
ns,
{ killCursors: ns.collection, cursors: cursorIds },
{ fullResult: true, ...options },
{ [kFullResult]: true, ...options },
(err, response) => {
if (err || !response) return callback(err);
if (response.cursorNotFound) {
Expand Down Expand Up @@ -774,7 +776,7 @@ function write(
requestId: command.requestId,
cb: callback,
session: options.session,
fullResult: typeof options.fullResult === 'boolean' ? options.fullResult : false,
fullResult: !!options[kFullResult],
noResponse: typeof options.noResponse === 'boolean' ? options.noResponse : false,
documentsReturnedIn: options.documentsReturnedIn,
command: !!options.command,
Expand Down
7 changes: 2 additions & 5 deletions src/operations/command.ts
Expand Up @@ -31,7 +31,7 @@ export interface CommandOperationOptions
extends OperationOptions,
WriteConcernOptions,
ExplainOptions {
/** Return the full server response for the command */
/** @deprecated This option does nothing */
fullResponse?: boolean;
/** Specify a read concern and level for the collection. (only MongoDB 3.2 or higher supported) */
readConcern?: ReadConcernLike;
Expand Down Expand Up @@ -66,7 +66,6 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
readConcern?: ReadConcern;
writeConcern?: WriteConcern;
explain?: Explain;
fullResponse?: boolean;
logger?: Logger;

constructor(parent?: OperationParent, options?: CommandOperationOptions) {
Expand All @@ -87,8 +86,6 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {

this.readConcern = ReadConcern.fromOptions(options);
this.writeConcern = WriteConcern.fromOptions(options);
this.fullResponse =
options && typeof options.fullResponse === 'boolean' ? options.fullResponse : false;

// TODO(NODE-2056): make logger another "inheritable" property
if (parent && parent.logger) {
Expand Down Expand Up @@ -169,6 +166,6 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
}
}

server.command(this.ns, cmd, { fullResult: !!this.fullResponse, ...options }, callback);
server.command(this.ns, cmd, options, callback);
}
}
2 changes: 1 addition & 1 deletion src/operations/distinct.ts
Expand Up @@ -80,7 +80,7 @@ export class DistinctOperation extends CommandOperation<any[]> {
return;
}

callback(undefined, this.options.fullResponse || this.explain ? result : result.values);
callback(undefined, this.explain ? result : result.values);
});
}
}
Expand Down
1 change: 0 additions & 1 deletion src/operations/find.ts
Expand Up @@ -166,7 +166,6 @@ export class FindOperation extends CommandOperation<Document> {
this.ns,
findCommand,
{
fullResult: !!this.fullResponse,
...this.options,
...this.bsonOptions,
documentsReturnedIn: 'firstBatch',
Expand Down
1 change: 0 additions & 1 deletion src/operations/operation.ts
Expand Up @@ -48,7 +48,6 @@ export abstract class AbstractOperation<TResult = any> {
cmd!: Document;
readPreference: ReadPreference;
server!: Server;
fullResponse?: boolean;
bypassPinningCheck: boolean;

// BSON serialization options
Expand Down

0 comments on commit dfc39d1

Please sign in to comment.