From 778928f3efe409af53e0fb491beb429a66ab0e5a Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Fri, 9 Aug 2019 09:31:47 -0400 Subject: [PATCH] refactor(command): support full response as command op option We were mutating the passed in `options` in order to convey that a given operation should return the full server response. Now this is passed in through an option in the operation constructor. --- lib/operations/aggregate.js | 4 +--- lib/operations/command_v2.js | 9 ++++++--- lib/operations/list_collections.js | 3 +-- lib/operations/list_indexes.js | 3 +-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/operations/aggregate.js b/lib/operations/aggregate.js index b9fc0f112e..e0f2da84e1 100644 --- a/lib/operations/aggregate.js +++ b/lib/operations/aggregate.js @@ -12,9 +12,7 @@ const MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8; class AggregateOperation extends CommandOperationV2 { constructor(parent, pipeline, options) { - // ensure we receive an unchanged raw response from the server (for cursor logic) - options.full = true; - super(parent, options); + super(parent, options, { fullResponse: true }); this.target = parent.s.namespace && parent.s.namespace.collection diff --git a/lib/operations/command_v2.js b/lib/operations/command_v2.js index c8f681b14a..8df703fdca 100644 --- a/lib/operations/command_v2.js +++ b/lib/operations/command_v2.js @@ -12,7 +12,7 @@ const MongoError = require('../error').MongoError; const SUPPORTS_WRITE_CONCERN_AND_COLLATION = 5; class CommandOperationV2 extends OperationBase { - constructor(parent, options) { + constructor(parent, options, operationOptions) { super(options); this.ns = parent.s.namespace.withCollection('$cmd'); @@ -21,6 +21,10 @@ class CommandOperationV2 extends OperationBase { this.writeConcern = resolveWriteConcern(parent, this.options); this.explain = false; + if (operationOptions && typeof operationOptions.fullResponse === 'boolean') { + this.fullResponse = true; + } + // TODO: A lot of our code depends on having the read preference in the options. This should // go away, but also requires massive test rewrites. this.options.readPreference = this.readPreference; @@ -78,14 +82,13 @@ class CommandOperationV2 extends OperationBase { this.logger.debug(`executing command ${JSON.stringify(cmd)} against ${this.ns}`); } - let fullResponse = this.options.full; server.command(this.ns.toString(), cmd, this.options, (err, result) => { if (err) { callback(err, null); return; } - if (fullResponse) { + if (this.fullResponse) { callback(null, result); return; } diff --git a/lib/operations/list_collections.js b/lib/operations/list_collections.js index 8015a83e01..ee01d31e85 100644 --- a/lib/operations/list_collections.js +++ b/lib/operations/list_collections.js @@ -26,8 +26,7 @@ function listCollectionsTransforms(databaseName) { class ListCollectionsOperation extends CommandOperationV2 { constructor(db, filter, options) { - super(db, options); - this.options.full = true; + super(db, options, { fullResponse: true }); this.db = db; this.filter = filter; diff --git a/lib/operations/list_indexes.js b/lib/operations/list_indexes.js index 2ab128eacf..302a31b7c8 100644 --- a/lib/operations/list_indexes.js +++ b/lib/operations/list_indexes.js @@ -9,8 +9,7 @@ const LIST_INDEXES_WIRE_VERSION = 3; class ListIndexesOperation extends CommandOperationV2 { constructor(collection, options) { - super(collection, options); - this.options.full = true; + super(collection, options, { fullResponse: true }); this.collectionNamespace = collection.s.namespace; }