Skip to content

Commit 778928f

Browse files
mbroadstdaprahamian
authored andcommitted
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.
1 parent 6acef6d commit 778928f

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

lib/operations/aggregate.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ const MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8;
1212

1313
class AggregateOperation extends CommandOperationV2 {
1414
constructor(parent, pipeline, options) {
15-
// ensure we receive an unchanged raw response from the server (for cursor logic)
16-
options.full = true;
17-
super(parent, options);
15+
super(parent, options, { fullResponse: true });
1816

1917
this.target =
2018
parent.s.namespace && parent.s.namespace.collection

lib/operations/command_v2.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const MongoError = require('../error').MongoError;
1212
const SUPPORTS_WRITE_CONCERN_AND_COLLATION = 5;
1313

1414
class CommandOperationV2 extends OperationBase {
15-
constructor(parent, options) {
15+
constructor(parent, options, operationOptions) {
1616
super(options);
1717

1818
this.ns = parent.s.namespace.withCollection('$cmd');
@@ -21,6 +21,10 @@ class CommandOperationV2 extends OperationBase {
2121
this.writeConcern = resolveWriteConcern(parent, this.options);
2222
this.explain = false;
2323

24+
if (operationOptions && typeof operationOptions.fullResponse === 'boolean') {
25+
this.fullResponse = true;
26+
}
27+
2428
// TODO: A lot of our code depends on having the read preference in the options. This should
2529
// go away, but also requires massive test rewrites.
2630
this.options.readPreference = this.readPreference;
@@ -78,14 +82,13 @@ class CommandOperationV2 extends OperationBase {
7882
this.logger.debug(`executing command ${JSON.stringify(cmd)} against ${this.ns}`);
7983
}
8084

81-
let fullResponse = this.options.full;
8285
server.command(this.ns.toString(), cmd, this.options, (err, result) => {
8386
if (err) {
8487
callback(err, null);
8588
return;
8689
}
8790

88-
if (fullResponse) {
91+
if (this.fullResponse) {
8992
callback(null, result);
9093
return;
9194
}

lib/operations/list_collections.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ function listCollectionsTransforms(databaseName) {
2626

2727
class ListCollectionsOperation extends CommandOperationV2 {
2828
constructor(db, filter, options) {
29-
super(db, options);
30-
this.options.full = true;
29+
super(db, options, { fullResponse: true });
3130

3231
this.db = db;
3332
this.filter = filter;

lib/operations/list_indexes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const LIST_INDEXES_WIRE_VERSION = 3;
99

1010
class ListIndexesOperation extends CommandOperationV2 {
1111
constructor(collection, options) {
12-
super(collection, options);
13-
this.options.full = true;
12+
super(collection, options, { fullResponse: true });
1413

1514
this.collectionNamespace = collection.s.namespace;
1615
}

0 commit comments

Comments
 (0)