Skip to content

Commit 86f5ba5

Browse files
mbroadstdaprahamian
authored andcommitted
feat: support explain operations in CommandOperationV2
This adds an extra field to the `CommandOperationV2` base class that informs command construction to support explain operations.
1 parent 0d738f5 commit 86f5ba5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/operations/command_v2.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ class CommandOperationV2 extends OperationBase {
88
super(options);
99

1010
this.ns = parent.s.namespace.withCollection('$cmd');
11-
this.readPreference = resolveReadPreference(parent, options);
12-
this.readConcern = resolveReadConcern(parent, options);
13-
this.writeConcern = resolveWriteConcern(parent, options);
11+
this.readPreference = resolveReadPreference(parent, this.options);
12+
this.readConcern = resolveReadConcern(parent, this.options);
13+
this.writeConcern = resolveWriteConcern(parent, this.options);
14+
this.explain = false;
1415

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

29+
let fullResponse = this.options.full;
30+
if (this.explain) {
31+
cmd = { explain: cmd };
32+
fullResponse = false;
33+
}
34+
2835
server.command(this.ns.toString(), cmd, this.options, (err, result) => {
2936
if (err) {
3037
callback(err, null);
3138
return;
3239
}
3340

34-
// full response was requested
35-
if (this.options.full) {
41+
if (fullResponse) {
3642
callback(null, result);
3743
return;
3844
}

0 commit comments

Comments
 (0)