Skip to content
Merged
Show file tree
Hide file tree
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 Apr 12, 2023
f602a6a
add tests
nbbeeken Apr 12, 2023
3b6cd29
test: runCommand expectations
nbbeeken Apr 13, 2023
32b8517
fix: title of tests
nbbeeken Apr 14, 2023
fd4853b
fix: stableAPI tests
nbbeeken Apr 14, 2023
a85f78a
fix: runOnRequirement needs to be array, transaction test cannot run …
nbbeeken Apr 14, 2023
062f595
test: fix schemaVersion and db options
nbbeeken Apr 14, 2023
89ba12a
fix: minServerVersion and remove "final" phrasing
nbbeeken Apr 14, 2023
d31ea7f
fix: test titles
nbbeeken Apr 17, 2023
d812dcd
fixes
nbbeeken Apr 17, 2023
3d24125
test fixes and phrasing
nbbeeken Apr 17, 2023
3a59c1e
fix: csot phrasing
nbbeeken Apr 17, 2023
1ec8bb3
suggestions
nbbeeken Apr 19, 2023
2c8a70d
fix: link to our own specs
nbbeeken Apr 19, 2023
8f22c64
fix: move deviations section and link to crud
nbbeeken Apr 19, 2023
7f08203
fix: add mention of the driver applying to lsid
nbbeeken Apr 19, 2023
06f6a51
fix: assume read for server selection
nbbeeken Apr 19, 2023
83b1174
fix: non-retryable
nbbeeken Apr 19, 2023
b8e3cbe
fix: add must not check language
nbbeeken Apr 19, 2023
2dd7d6b
fix: update immutable section
nbbeeken Apr 19, 2023
4a80fb2
fix: use anchors
nbbeeken Apr 19, 2023
50c9e16
fix: consistently refer to it as "RunCommand"
nbbeeken Apr 19, 2023
33f1628
fix: session should mention connection instead of server
nbbeeken Apr 19, 2023
d1017f6
fix: apply prose fixes
nbbeeken Apr 20, 2023
36a140b
chore: changelog bump and removal
nbbeeken Apr 20, 2023
4a6f4af
test: rename and fix
nbbeeken Apr 20, 2023
7119162
fix: lower schema version
nbbeeken Apr 20, 2023
602adec
chore: use db name, shortform commands
nbbeeken Apr 20, 2023
90f7382
chore: shortform options
nbbeeken Apr 20, 2023
d5b4a07
chore: consistent with* naming
nbbeeken Apr 20, 2023
731da75
fix: empty doc array and indentation
nbbeeken Apr 20, 2023
9e4b568
fix: nest RP in mode
nbbeeken Apr 20, 2023
c8a3663
fix: set useMultipleMongoses to false
nbbeeken Apr 20, 2023
11b28d3
fix: client error and topologies
nbbeeken Apr 20, 2023
f00f97d
fix: changelog formatting
nbbeeken Apr 20, 2023
8452a90
fix: minor test fixes
nbbeeken Apr 20, 2023
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
185 changes: 185 additions & 0 deletions source/run-command/run-command.rst
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 {
/**
* 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
*
* @see https://www.mongodb.com/docs/manual/core/read-preference/
*/
readPreference?: ReadPreference;

/**
* An optional explicit client session.
* The associated logical session id (`lsid`) MUST be applied to the command.
*
* @see https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions
*/
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.

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.

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.

* 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.
To facilitate selecting the server the command should be sent to a driver's runCommand MUST accept an optional Read Preference option.

* 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.

* 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.
If a session is not provided the driver MUST attach an implicit session if the selected server supports sessions.

Every ClientSession has a corresponding Logical Session ID representing the server side session ID.
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.
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.

* 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>`_

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.

* 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.
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.
Drivers MUST NOT attempt to check the command document for the presence of a ``maxTimeMS`` field.
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.
19 changes: 19 additions & 0 deletions source/run-command/tests/README.rst
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.
Loading