Skip to content

Commit 96c8ab4

Browse files
authored
fix(NODE-3377): driver should allow arbitrary explain levels (#2961)
1 parent 4c25984 commit 96c8ab4

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

lib/explain.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
const MongoError = require('./core/error').MongoError;
44

5-
const ExplainVerbosity = {
6-
queryPlanner: 'queryPlanner',
7-
queryPlannerExtended: 'queryPlannerExtended',
8-
executionStats: 'executionStats',
9-
allPlansExecution: 'allPlansExecution'
10-
};
11-
125
/**
136
* @class
14-
* @property {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'} verbosity The verbosity mode for the explain output.
7+
* @property {string} verbosity The verbosity mode for the explain output, e.g.: 'queryPlanner', 'queryPlannerExtended', 'executionStats', 'allPlansExecution'.
158
*/
169
class Explain {
1710
/**
@@ -21,7 +14,7 @@ class Explain {
2114
* and false as "queryPlanner". Prior to server version 3.6, aggregate()
2215
* ignores the verbosity parameter and executes in "queryPlanner".
2316
*
24-
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [verbosity] The verbosity mode for the explain output.
17+
* @param {string|boolean} [verbosity] The verbosity mode for the explain output.
2518
*/
2619
constructor(verbosity) {
2720
if (typeof verbosity === 'boolean') {
@@ -35,7 +28,7 @@ class Explain {
3528
* Construct an Explain given an options object.
3629
*
3730
* @param {object} [options] The options object from which to extract the explain.
38-
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output
31+
* @param {string|boolean} [options.explain] The verbosity mode for the explain output.
3932
* @return {Explain}
4033
*/
4134
static fromOptions(options) {
@@ -44,11 +37,11 @@ class Explain {
4437
}
4538

4639
const explain = options.explain;
47-
if (typeof explain === 'boolean' || explain in ExplainVerbosity) {
40+
if (typeof explain === 'boolean' || typeof explain === 'string') {
4841
return new Explain(options.explain);
4942
}
5043

51-
throw new MongoError(`explain must be one of ${Object.keys(ExplainVerbosity)} or a boolean`);
44+
throw new MongoError(`explain must be a string or a boolean`);
5245
}
5346
}
5447

0 commit comments

Comments
 (0)