Skip to content

Commit 09a5110

Browse files
authored
(DOCSP-15528): Add Stable API options to the Mongo() Constructor (#2211)
* Add API options to Mongo constructor * copy review feedback * copy review feedback 2 * tech review feedback
1 parent 9c258a2 commit 09a5110

File tree

3 files changed

+105
-62
lines changed

3 files changed

+105
-62
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. list-table::
2+
:widths: 20,10,70
3+
:header-rows: 1
4+
5+
* - |param|
6+
- Type
7+
- Description
8+
9+
* - |apiVersion|
10+
- string
11+
- Specifies the API Version. ``"1"`` is
12+
currently the only supported version.
13+
14+
* - |strict|
15+
- boolean
16+
- If ``true``, using a command that is not
17+
part of the declared API version returns an
18+
:ref:`APIStrictError <api-strict-resp>` error. If you specify
19+
|strict|, you must also specify |apiVersion|.
20+
21+
If not specified, defaults to ``false``.
22+
23+
* - |deprecation|
24+
- boolean
25+
- If ``true``, using a command or behavior that is deprecated
26+
in the specified API version returns an
27+
:ref:`APIDeprecationError <api-deprecation-resp>`. If you specify
28+
|deprecation|, you must also specify |apiVersion|.
29+
30+
If not specified, defaults to ``false``.

source/reference/method/Mongo.txt

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ Mongo()
77
.. contents:: On this page
88
:local:
99
:backlinks: none
10-
:depth: 1
10+
:depth: 2
1111
:class: singlecol
1212

1313
Description
1414
-----------
1515

1616
.. versionchanged:: 4.2
1717

18-
.. method:: Mongo(host, {+auto-encrypt-options+})
18+
.. method:: Mongo(host, {+auto-encrypt-options+}, api)
1919

2020
JavaScript constructor to instantiate a database connection from
2121
:binary:`~bin.mongosh` or from a JavaScript file.
@@ -36,21 +36,19 @@ Description
3636

3737
- string
3838

39-
- Optional. The host, either in the form of ``<host>`` or
39+
- *Optional*. The host, either in the form of ``<host>`` or
4040
``<host><:port>``.
4141

4242
If omitted, :method:`Mongo` instantiates a connection to the
4343
localhost interface on the default port ``27017``.
4444

4545
* - ``{+auto-encrypt-options+}``
4646

47-
- Document
47+
- document
4848

49-
- *Optional*
50-
51-
.. versionadded:: 4.2
52-
53-
Configuration parameters for enabling
49+
- .. versionadded:: 4.2
50+
51+
*Optional*. Configuration parameters for enabling
5452
:ref:`manual-csfle-feature`.
5553

5654
``{+auto-encrypt-options+}`` overrides the
@@ -59,14 +57,22 @@ Description
5957
inherits the client-side field level encryption configuration
6058
of the current database connection.
6159

62-
For documentation of usage and syntax, see
63-
:ref:`{+auto-encrypt-options+}`.
60+
See :ref:`{+auto-encrypt-options+}` for usage and syntax
61+
details.
62+
63+
* - ``api``
64+
65+
- document
66+
67+
- *Optional*. Configuration options for enabling the
68+
:ref:`Stable API <stable-api>`.
69+
70+
See :ref:`mongo-api-options` for usage and syntax details.
6471

6572
.. seealso::
6673

6774
:method:`Mongo.getDB()` and :method:`db.getMongo()`
6875

69-
7076
.. _{+auto-encrypt-options+}:
7177

7278
``{+title-auto-encrypt-options+}``
@@ -261,9 +267,32 @@ following parameters:
261267
indexed fields without the ``crypt_shared`` library. For details,
262268
see :ref:`qe-reference-mongo-client`.
263269

264-
Example
270+
271+
.. _mongo-api-options:
272+
273+
``api``
265274
-------
266275

276+
The ``api`` parameter specifies configuration options for the
277+
:ref:`Stable API <stable-api>`. You can enable or disable optional
278+
behavior using the following options:
279+
280+
.. include:: /includes/stable-api-options.rst
281+
282+
.. |param| replace:: Option
283+
.. |apiVersion| replace:: ``version``
284+
.. |strict| replace:: ``strict``
285+
.. |deprecation| replace:: ``deprecationErrors``
286+
287+
The ``api`` parameter has the following syntax:
288+
289+
.. code-block:: javascript
290+
291+
{ api: { version: <string>, strict: <boolean>, deprecationErrors: <boolean> } }
292+
293+
Examples
294+
--------
295+
267296
Connect to a MongoDB Cluster
268297
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
269298

@@ -284,8 +313,8 @@ Issue operations against the ``cluster`` object to interact with the
284313

285314
.. _mongo-connection-client-side-encryption-enabled:
286315

287-
Connect to a MongoDB Cluster with Client-Side Encryption Enabled
288-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
316+
Connect to a Cluster with Client-Side Encryption Enabled
317+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
289318

290319
Configuring client-side field level encryption for a :ref:`locally
291320
managed key <field-level-encryption-local-kms>` requires specifying a
@@ -345,8 +374,8 @@ a complete list of client-side field level encryption methods.
345374

346375
.. _mongo-connection-automatic-client-side-encryption-enabled:
347376

348-
Connect to a MongoDB Cluster with Automatic Client-Side Encryption Enabled
349-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
377+
Connect to a Cluster with Automatic Client-Side Encryption Enabled
378+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
350379

351380
Configuring client-side field level encryption for a :ref:`locally
352381
managed key <field-level-encryption-local-kms>` requires specifying a
@@ -431,3 +460,23 @@ the specified data encryption key can decrypt the field.
431460

432461
See :doc:`/reference/method/js-client-side-field-level-encryption` for
433462
a complete list of client-side field level encryption methods.
463+
464+
Connect to a Cluster with the Stable API Enabled
465+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
466+
467+
The following operation creates a new connection object from within a
468+
:binary:`~bin.mongosh` session. The :ref:`mongo-api-options` option
469+
enables Stable API V1 and specifies that you cannot
470+
run deprecated command or commands outside of the Stable API.
471+
472+
.. code-block:: javascript
473+
474+
cluster = Mongo(
475+
"mongodb://mymongo.example.net:27017/?replicaSet=myMongoCluster",
476+
null,
477+
{ api: { version: "1", strict: true, deprecationErrors: true } }
478+
)
479+
480+
To interact with the ``mymongo.example.net:27017`` cluster, issue
481+
operations against the ``cluster`` object. For a full list of Stable API
482+
commands, see :ref:`<api-v1-command-list>`.

source/reference/stable-api.txt

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -534,52 +534,16 @@ your application's MongoDB driver connection code. Check the MongoDB
534534
driver documentation for the driver you use in your application for
535535
more information:
536536

537-
.. list-table::
538-
:widths: 30,30,40
539-
:header-rows: 1
540-
541-
* - Parameter
542-
543-
- Type
544-
545-
- Description
546-
547-
* - :ref:`apiVersion <api-version-desc>`
548-
549-
- string
550-
551-
- .. _api-version-desc:
552-
553-
API Version. ``"1"`` is currently the only supported API Version.
554-
555-
See :ref:`APIVersionError <api-vers-resp>`.
556-
557-
* - :ref:`apiStrict <api-strict-desc>`
537+
.. _api-version-desc:
538+
.. _api-strict-desc:
539+
.. _api-depr-desc:
558540

559-
- boolean
560-
561-
- .. _api-strict-desc:
562-
563-
If ``true``, your application can only use commands defined for
564-
your specified :ref:`apiVersion <api-version-desc>`.
565-
566-
If not specified, defaults to ``false``.
567-
568-
See :ref:`APIStrictError <api-strict-resp>`.
569-
570-
* - :ref:`apiDeprecationErrors <api-depr-desc>`
571-
572-
- boolean
573-
574-
- .. _api-depr-desc:
575-
576-
If ``true``, your application errors if it invokes a command or
577-
behavior that is deprecated in the specified
578-
:ref:`apiVersion <api-version-desc>`.
579-
580-
If not specified, defaults to ``false``.
581-
582-
See :ref:`APIDeprecationError <api-deprecation-resp>`.
541+
.. include:: /includes/stable-api-options.rst
542+
543+
.. |param| replace:: Parameter
544+
.. |apiVersion| replace:: :ref:`apiVersion <api-version-desc>`
545+
.. |strict| replace:: :ref:`apiStrict <api-strict-desc>`
546+
.. |deprecation| replace:: :ref:`apiDeprecationErrors <api-depr-desc>`
583547

584548

585549
Behavior

0 commit comments

Comments
 (0)