Skip to content

Commit

Permalink
feat: support explain operations in CommandOperationV2
Browse files Browse the repository at this point in the history
This adds an extra field to the `CommandOperationV2` base class
that informs command construction to support explain operations.
  • Loading branch information
mbroadst authored and daprahamian committed Aug 13, 2019
1 parent 0d738f5 commit 86f5ba5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/operations/command_v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ class CommandOperationV2 extends OperationBase {
super(options);

this.ns = parent.s.namespace.withCollection('$cmd');
this.readPreference = resolveReadPreference(parent, options);
this.readConcern = resolveReadConcern(parent, options);
this.writeConcern = resolveWriteConcern(parent, options);
this.readPreference = resolveReadPreference(parent, this.options);
this.readConcern = resolveReadConcern(parent, this.options);
this.writeConcern = resolveWriteConcern(parent, this.options);
this.explain = false;

// TODO(NODE-2056): make logger another "inheritable" property
if (parent.s.logger) {
Expand All @@ -25,14 +26,19 @@ class CommandOperationV2 extends OperationBase {
this.logger.debug(`executing command ${JSON.stringify(cmd)} against ${this.ns}`);
}

let fullResponse = this.options.full;
if (this.explain) {
cmd = { explain: cmd };
fullResponse = false;
}

server.command(this.ns.toString(), cmd, this.options, (err, result) => {
if (err) {
callback(err, null);
return;
}

// full response was requested
if (this.options.full) {
if (fullResponse) {
callback(null, result);
return;
}
Expand Down

0 comments on commit 86f5ba5

Please sign in to comment.