-
Notifications
You must be signed in to change notification settings - Fork 246
DRIVERS-2577: add a runCommand specification #1389
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
Changes from 12 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
50fdf4b
DRIVERS-2533: runCommand specification
nbbeeken f602a6a
add tests
nbbeeken 3b6cd29
test: runCommand expectations
nbbeeken 32b8517
fix: title of tests
nbbeeken fd4853b
fix: stableAPI tests
nbbeeken a85f78a
fix: runOnRequirement needs to be array, transaction test cannot run …
nbbeeken 062f595
test: fix schemaVersion and db options
nbbeeken 89ba12a
fix: minServerVersion and remove "final" phrasing
nbbeeken d31ea7f
fix: test titles
nbbeeken d812dcd
fixes
nbbeeken 3d24125
test fixes and phrasing
nbbeeken 3a59c1e
fix: csot phrasing
nbbeeken 1ec8bb3
suggestions
nbbeeken 2c8a70d
fix: link to our own specs
nbbeeken 8f22c64
fix: move deviations section and link to crud
nbbeeken 7f08203
fix: add mention of the driver applying to lsid
nbbeeken 06f6a51
fix: assume read for server selection
nbbeeken 83b1174
fix: non-retryable
nbbeeken b8e3cbe
fix: add must not check language
nbbeeken 2dd7d6b
fix: update immutable section
nbbeeken 4a80fb2
fix: use anchors
nbbeeken 50c9e16
fix: consistently refer to it as "RunCommand"
nbbeeken 33f1628
fix: session should mention connection instead of server
nbbeeken d1017f6
fix: apply prose fixes
nbbeeken 36a140b
chore: changelog bump and removal
nbbeeken 4a6f4af
test: rename and fix
nbbeeken 7119162
fix: lower schema version
nbbeeken 602adec
chore: use db name, shortform commands
nbbeeken 90f7382
chore: shortform options
nbbeeken d5b4a07
chore: consistent with* naming
nbbeeken 731da75
fix: empty doc array and indentation
nbbeeken 9e4b568
fix: nest RP in mode
nbbeeken c8a3663
fix: set useMultipleMongoses to false
nbbeeken 11b28d3
fix: client error and topologies
nbbeeken f00f97d
fix: changelog formatting
nbbeeken 8452a90
fix: minor test fixes
nbbeeken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
=========== | ||
Run Command | ||
=========== | ||
|
||
:Title: Run Command | ||
:Status: Implementing | ||
:Minimum Server Version: N/A | ||
|
||
.. contents:: | ||
|
||
-------- | ||
|
||
Abstract | ||
======== | ||
This specification defines requirements and behaviors for drivers' run command and related APIs. | ||
|
||
|
||
META | ||
==== | ||
|
||
The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", | ||
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this | ||
document are to be interpreted as described in `RFC 2119 | ||
<https://www.ietf.org/rfc/rfc2119.txt>`_. | ||
|
||
Specification | ||
============= | ||
|
||
----- | ||
Terms | ||
----- | ||
Command | ||
A structure representing a BSON document that has a shape matching a supported MongoDB operation. | ||
|
||
--------------------------- | ||
Implementation requirements | ||
--------------------------- | ||
|
||
All drivers MAY offer the operations defined in the following sections. | ||
This does not preclude a driver from offering more. | ||
|
||
-------------- | ||
``runCommand`` | ||
-------------- | ||
|
||
The following represents how a runCommand API SHOULD be exposed. | ||
|
||
.. code:: typescript | ||
|
||
interface Db { | ||
nbbeeken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
/** | ||
* Takes an argument representing an arbitrary BSON document and executes it against the server. | ||
*/ | ||
runCommand(command: BSONDocument, options: RunCommandOptions): BSONDocument; | ||
} | ||
|
||
interface RunCommandOptions { | ||
/** | ||
* An optional readPreference setting to apply to server selection logic. | ||
* This value MUST be applied to the command document as the $readPreference global command argument if not set to primary. | ||
* | ||
* @defaultValue primary | ||
nbbeeken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
* | ||
* @see https://www.mongodb.com/docs/manual/core/read-preference/ | ||
jmikola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
*/ | ||
readPreference?: ReadPreference; | ||
|
||
/** | ||
* An optional explicit client session. | ||
* The associated logical session id (`lsid`) MUST be applied to the command. | ||
durran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
* | ||
* @see https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions | ||
jmikola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
*/ | ||
session?: ClientSession; | ||
|
||
/** | ||
* An optional timeout option to govern the amount of time that a single operation can execute before control is returned to the user. | ||
* This timeout applies to all of the work done to execute the operation, including but not limited to server selection, connection checkout, and server-side execution. | ||
* | ||
* @ see https://github.com/mongodb/specifications/blob/master/source/client-side-operations-timeout/client-side-operations-timeout.rst | ||
*/ | ||
timeoutMS?: number; | ||
} | ||
|
||
Deviations | ||
^^^^^^^^^^ | ||
|
||
* Drivers MAY rename their API to match the language syntax. | ||
jmikola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
RunCommand implementation details | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
RunCommand provides a way to access MongoDB server commands directly without requiring a driver to implement a bespoke helper. | ||
The API is intended to take a document from a user and apply a number of common driver internal concerns before forwarding the command to a server. | ||
In general, a driver SHOULD avoid inspecting or modifying the user's command document in an effort to remain forward compatible with any potential server commands. | ||
|
||
Drivers that have historically modified user input SHOULD strive to instead clone the input such that appended fields do not affect the user's input. | ||
durran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
OP_MSG | ||
"""""" | ||
|
||
The ``$db`` global command argument MUST be sent on the command sent to the server and it MUST correspond to the database name the runCommand API was invoked on. | ||
nbbeeken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
* See OP_MSG's section on `Global Command Arguments <https://github.com/mongodb/specifications/blob/master/source/message/OP_MSG.rst#global-command-arguments>`_ | ||
|
||
ReadPreference | ||
"""""""""""""" | ||
|
||
A driver's runCommand implementation MUST assume all commands are read operations. | ||
jmikola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
To facilitate selecting the server the command should be sent to a driver's runCommand MUST accept an optional Read Preference option. | ||
nbbeeken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
* See Server Selection's section on `Use of read preferences with commands <https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#use-of-read-preferences-with-commands>`_ | ||
|
||
If the provided Read Preference is NOT primary, the command sent MUST include the ``$readPreference`` global command argument. | ||
nbbeeken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
* See OP_MSG's section on `Global Command Arguments <https://github.com/mongodb/specifications/blob/master/source/message/OP_MSG.rst#global-command-arguments>`_ | ||
|
||
Driver Sessions | ||
""""""""""""""" | ||
|
||
A driver's runCommand API MUST provide an optional session option to support explicit sessions and transactions. | ||
dariakp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
If a session is not provided the driver MUST attach an implicit session if the selected server supports sessions. | ||
jmikola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Every ClientSession has a corresponding Logical Session ID representing the server side session ID. | ||
nbbeeken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
The Logical Session ID MUST be included under ``lsid`` in the command sent to the server without modifying user input. | ||
|
||
* See Driver Sessions' section on `Sending the session ID to the server on all commands <https://github.com/mongodb/specifications/blob/master/source/sessions/driver-sessions.rst#sending-the-session-id-to-the-server-on-all-commands>`_ | ||
|
||
Transactions | ||
"""""""""""" | ||
|
||
If RunCommand is used within a Transaction the read preference MUST be sourced from the Transaction's options. | ||
nbbeeken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
The command sent to the server MUST include the transaction specific fields, summarized as follows: | ||
|
||
* If ``runCommand`` is executing within a transaction: | ||
|
||
* ``autocommit`` - The autocommit flag MUST be set to false. | ||
* ``txnNumber`` - MUST be set. | ||
|
||
* If ``runCommand`` is the first operation of the transaction: | ||
|
||
* ``startTransaction`` - MUST be set to true. | ||
* ``readConcern`` - MUST be set to the Transaction's readConcern setting if it is NOT the default. | ||
nbbeeken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
* See Transactions' section on `Generic RunCommand helper within a transaction <https://github.com/mongodb/specifications/blob/master/source/transactions/transactions.rst#generic-runcommand-helper-within-a-transaction>`_ | ||
nbbeeken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
ReadConcern and WriteConcern | ||
"""""""""""""""""""""""""""" | ||
|
||
A RunCommand API MUST NOT support Read Concern and Write Concern options. | ||
Additionally, unless within a transaction, the command sent MUST NOT have any Read Concern or Write Concern fields applied that may be inherited from client, database, or collection options. | ||
nbbeeken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
* See Read Concern's section on `Generic Command Method <https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.rst#generic-command-method>`_ | ||
* See Write Concern's section on `Generic Command Method <https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.rst#generic-command-method-1>`_ | ||
|
||
Retryability | ||
"""""""""""" | ||
|
||
All commands passed to runCommand are considered non-retryable reads. | ||
jmikola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Drivers MUST NOT inspect the command to determine if it is a write and MUST NOT attach a ``txnNumber``. | ||
|
||
* See Retryable Reads' section on `Unsupported Read Operations <https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.rst#unsupported-read-operations>`_ | ||
* See Retryable Writes' section on `Behavioral Changes for Write Commands <https://github.com/mongodb/specifications/blob/master/source/retryable-writes/retryable-writes.rst#behavioral-changes-for-write-commands>`_ | ||
|
||
Stable API | ||
"""""""""" | ||
|
||
The command sent MUST attach stable API fields as configured on the MongoClient. | ||
|
||
* See Stable API's section on `Generic Command Helper Behaviour <https://github.com/mongodb/specifications/blob/master/source/versioned-api/versioned-api.rst#generic-command-helper>`_ | ||
|
||
Client Side Operations Timeout | ||
"""""""""""""""""""""""""""""" | ||
|
||
A driver's runCommand API MUST provide an optional timeoutMS option to support client side operations timeout. | ||
nbbeeken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Drivers MUST NOT attempt to check the command document for the presence of a ``maxTimeMS`` field. | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Drivers MUST document the behavior of runCommand if a ``maxTimeMS`` field is already set on the command (such as overwriting the command field). | ||
|
||
* See Client Side Operations Timeout's section on `runCommand <https://github.com/mongodb/specifications/blob/master/source/client-side-operations-timeout/client-side-operations-timeout.rst#runcommand>`_ | ||
* See Client Side Operations Timeout's section on `runCommand behavior <https://github.com/mongodb/specifications/blob/master/source/client-side-operations-timeout/client-side-operations-timeout.rst#runcommand-behavior>`_ | ||
|
||
Changelog | ||
========= | ||
|
||
:2023-03-28: Add run command specification. | ||
jmikola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
================= | ||
Run Command Tests | ||
================= | ||
|
||
.. contents:: | ||
|
||
---- | ||
|
||
Introduction | ||
============ | ||
|
||
The YAML and JSON files in the ``unified`` sub-directories are platform-independent tests | ||
that drivers can use to prove their conformance to the RunCommand spec. Tests in the | ||
``unified`` directory are written using the `Unified Test Format <../../unified-test-format/unified-test-format.rst>`_. | ||
|
||
Changelog | ||
========= | ||
|
||
:2023-04-12: Add runCommand tests. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.