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

feat: add explain support #2626

Merged
merged 6 commits into from
Nov 30, 2020
Merged

Conversation

HanaPearlman
Copy link
Contributor

@HanaPearlman HanaPearlman commented Nov 18, 2020

Port explain support to 3.6.

The logical changes are the same, but some things had to occur in different places: Since OperationBase is the only shared class between all of the explainable ops, the explain property is on OperationBase, and decorateWithExplain is used in a few more places.

@@ -310,6 +309,7 @@ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot', 'oplogReplay']
* @param {boolean} [options.noCursorTimeout] The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
* @param {boolean} [options.allowDiskUse] Enables writing to temporary files on the server.
* @param {string|boolean} [options.explain] The verbosity mode for the explain output.
* @param {ClientSession} [options.session] optional session to use for this operation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not sure the best way to communicate what the valid values of options.explain are. We could list the valid strings and how the boolean values will be interpreted, which is what we do for readPreference, or we could link to some server documentation, which is what we do for hint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did suggest lower to put the strings in, if we put the strings in VSCode can suggest the strings to devs 🤷 but then it might error if there's a new string later.. Maybe the link is best

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go ahead with using the enum from 4.0 to check that the string passed in is a valid verbosity, then it will error if there's a new verbosity string added later anyway.

Since we went ahead with doing the valid verbosity check in 4.0, my thought is to go ahead and do that here as well, and list the strings within the type. More work for us later if a new string is added, though.


// If an explain operation was executed, don't process the server results
if (this.explain) return callback(undefined, r.result);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got rid of deleteCallback and updateCallback in common_functions and moved the body of the functions into the respective operation classes; this way we can reference this.explain (and it is consistent with master).

@HanaPearlman HanaPearlman force-pushed the NODE-2853/3.6/explain branch 2 times, most recently from b395273 to 3233d5e Compare November 19, 2020 16:00
@HanaPearlman HanaPearlman marked this pull request as ready for review November 19, 2020 17:27
lib/explain.js Outdated Show resolved Hide resolved
lib/explain.js Show resolved Hide resolved
lib/explain.js Outdated Show resolved Hide resolved
@@ -310,6 +309,7 @@ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot', 'oplogReplay']
* @param {boolean} [options.noCursorTimeout] The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
* @param {boolean} [options.allowDiskUse] Enables writing to temporary files on the server.
* @param {string|boolean} [options.explain] The verbosity mode for the explain output.
* @param {ClientSession} [options.session] optional session to use for this operation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did suggest lower to put the strings in, if we put the strings in VSCode can suggest the strings to devs 🤷 but then it might error if there's a new string later.. Maybe the link is best

Copy link
Contributor

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Barring the current issues we're having around testing LGTM 🙂

r.modifiedCount = r.result.nModified != null ? r.result.nModified : r.result.n;
r.upsertedId =
Array.isArray(r.result.upserted) && r.result.upserted.length > 0
? r.result.upserted[0] // FIXME(major): should be `r.result.upserted[0]._id`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this fixme is still relevant..

Copy link
Contributor

@emadum emadum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants