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-3511): deprecate fullResponse and remove associated buggy code paths #2943

Merged
merged 4 commits into from Aug 23, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -773,7 +775,7 @@ function write(
requestId: command.requestId,
cb: callback,
session: options.session,
fullResult: typeof options.fullResult === 'boolean' ? options.fullResult : false,
fullResult: !!options[kFullResult],
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
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