Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-3377): driver should allow arbitrary explain levels #2961

Merged
merged 1 commit into from
Aug 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions lib/explain.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

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

const ExplainVerbosity = {
queryPlanner: 'queryPlanner',
queryPlannerExtended: 'queryPlannerExtended',
executionStats: 'executionStats',
allPlansExecution: 'allPlansExecution'
};

/**
* @class
* @property {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'} verbosity The verbosity mode for the explain output.
* @property {string} verbosity The verbosity mode for the explain output, e.g.: 'queryPlanner', 'queryPlannerExtended', 'executionStats', 'allPlansExecution'.
*/
class Explain {
/**
Expand All @@ -21,7 +14,7 @@ class Explain {
* and false as "queryPlanner". Prior to server version 3.6, aggregate()
* ignores the verbosity parameter and executes in "queryPlanner".
*
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [verbosity] The verbosity mode for the explain output.
* @param {string|boolean} [verbosity] The verbosity mode for the explain output.
*/
constructor(verbosity) {
if (typeof verbosity === 'boolean') {
Expand All @@ -35,7 +28,7 @@ class Explain {
* Construct an Explain given an options object.
*
* @param {object} [options] The options object from which to extract the explain.
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output
* @param {string|boolean} [options.explain] The verbosity mode for the explain output.
* @return {Explain}
*/
static fromOptions(options) {
Expand All @@ -44,11 +37,11 @@ class Explain {
}

const explain = options.explain;
if (typeof explain === 'boolean' || explain in ExplainVerbosity) {
if (typeof explain === 'boolean' || typeof explain === 'string') {
return new Explain(options.explain);
}

throw new MongoError(`explain must be one of ${Object.keys(ExplainVerbosity)} or a boolean`);
throw new MongoError(`explain must be a string or a boolean`);
}
}

Expand Down