Skip to content

DOCSP-30358: Run a Command Fundamentals page #702

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

Merged
merged 7 commits into from
Jun 6, 2023

Conversation

rustagir
Copy link
Collaborator

@rustagir rustagir commented Jun 5, 2023

Pull Request Info

PR Reviewing Guidelines

JIRA - DOCSP-30358 and DOCSP-30119
Staging

Self-Review Checklist

  • Is this free of any warnings or errors in the RST?
  • Did you run a spell-check?
  • Did you run a grammar-check?
  • Are all the links working?

Copy link
Collaborator

@mongoKart mongoKart left a comment

Choose a reason for hiding this comment

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

nicely done. mostly questions and suggestions

- ``command()``, which returns the command response as a
``Document`` type. You can use this method with any database command.
- ``runCursorCommand()``, which returns the command response as an iterable
``RunCommandCursor`` type. You can use this method if your database command
Copy link
Collaborator

Choose a reason for hiding this comment

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

S: "only if"?

Suggested change
``RunCommandCursor`` type. You can use this method if your database command
``RunCommandCursor`` type. You can use this method only if your database command

Comment on lines 48 to 50
``command()`` and ``runCursorCommand()`` do not obey the read
preference you may have set on your ``Db`` object elsewhere in
your code. You can set a read preference for command execution by
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: What do they do instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added default value

``command()`` and ``runCursorCommand()`` do not obey the read
preference you may have set on your ``Db`` object elsewhere in
your code. You can set a read preference for command execution by
passing the relevant options object to either method:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: What makes the objects "relevant"? Does each method accept a different object format?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, RunCommandOptions and RunCursorCommandOptions. I can clarify the pairs

Comment on lines +64 to +65
Each method returns a ``Document`` object or a cursor that contains
the response from the database after the command has been executed. Each
Copy link
Collaborator

Choose a reason for hiding this comment

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

S: I'm guessing this means command() returns a Document and runCursorCommand returns a cursor. If so, can we clarify? By saying "Each method...", it sounds like each of the two methods will return one type or the other depending on some unspecified circumstance.


The following code shows how you can use the ``runCursorCommand()`` method to
run the ``checkMetadataConsistency`` command on the ``testDB`` database
and iterates through the results:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I: "iterates", with an s, suggests it's the second thing "The following code" is doing, after "shows how you can use...". To me, it's more natural that the code is showing how you can do two things: 1) use the command and 2) iterate through the results, in which case it should be "iterate", with no s

Suggested change
and iterates through the results:
and iterate through the results:


If you store the command response in a cursor, you see only the
command result documents when you access the contents of the cursor. You won't
see the ``ok``, ``operationTime``, and ``$clusterTime`` fields.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: is there a way to see this info when using a cursor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so. I can try printing the cursor a few different ways and see what happens, though.

Copy link
Collaborator Author

@rustagir rustagir Jun 5, 2023

Choose a reason for hiding this comment

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

after some testing it seems like you cant, but I will follow up with DBX

@rustagir rustagir requested a review from mongoKart June 5, 2023 20:29
Copy link
Collaborator

@mongoKart mongoKart left a comment

Choose a reason for hiding this comment

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

couple suggestions but lgtm otherwise

@@ -18,6 +18,13 @@ In this guide, you can learn how to run a database command with the
administrative and diagnostic tasks, such as fetching server statistics,
initializing a replica set, or running an aggregation pipeline.

.. important:: Use Driver Methods if Possible
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.. important:: Use Driver Methods if Possible
.. important:: Prefer Driver Methods to Database Commands

Comment on lines 23 to 26
The driver provides wrapper methods that produce the same results as
many database commands. We recommend that you check if there
is a driver method available to perform your desired action before you
execute a raw database command.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you remember exactly why this is? Node isn't even statically typed like C#/Java. If you do, could be helpful to include.

Suggested change
The driver provides wrapper methods that produce the same results as
many database commands. We recommend that you check if there
is a driver method available to perform your desired action before you
execute a raw database command.
The {+driver-short+} provides wrapper methods for many database commands.
These wrapper methods... [advantages].
If possible, use a driver method instead of a database command.

@rustagir rustagir merged commit 12e4e60 into mongodb:master Jun 6, 2023
rustagir added a commit that referenced this pull request Jun 6, 2023
* DOCSP-30358: run command fundamentals pg

* add to tree

* fix tree entry

* add note and some fixes

* move out of CURD

* MW PR fixes 1

* MW PR fixes 2

(cherry picked from commit 12e4e60)
mongoKart pushed a commit to mongoKart/docs-node that referenced this pull request Nov 3, 2023
* DOCSP-30358: run command fundamentals pg

* add to tree

* fix tree entry

* add note and some fixes

* move out of CURD

* MW PR fixes 1

* MW PR fixes 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants