Skip to content

Commit af64800

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

File tree

3 files changed

+102
-60
lines changed

3 files changed

+102
-60
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: 63 additions & 15 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, ClientSideFieldLevelEncryptionOptions)
18+
.. method:: Mongo(host, ClientSideFieldLevelEncryptionOptions, 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
* - ``ClientSideFieldLevelEncryptionOptions``
4646

47-
- Document
47+
- document
4848

49-
- *Optional*
50-
51-
.. versionadded:: 4.2
49+
- .. versionadded:: 4.2
5250

53-
Configuration parameters for enabling
51+
*Optional*. Configuration parameters for enabling
5452
:doc:`/core/security-client-side-encryption`.
5553

5654
``ClientSideFieldLevelEncryptionOptions`` overrides the
@@ -59,8 +57,16 @@ 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:`ClientSideFieldLevelEncryptionOptions`.
60+
See :ref:`ClientSideFieldLevelEncryptionOptions` for usage and syntax details.
61+
62+
* - ``api``
63+
64+
- document
65+
66+
- *Optional*. Configuration options for enabling the
67+
:ref:`Stable API <stable-api>`.
68+
69+
See :ref:`mongo-api-options` for usage and syntax details.
6470

6571
.. seealso::
6672

@@ -254,9 +260,31 @@ following parameters:
254260
level encryption rules and perform explicit (manual) per-field
255261
encryption.
256262

257-
Example
263+
.. _mongo-api-options:
264+
265+
``api``
258266
-------
259267

268+
The ``api`` parameter specifies configuration options for the
269+
:ref:`Stable API <stable-api>`. You can enable or disable optional
270+
behavior using the following options:
271+
272+
.. include:: /includes/stable-api-options.rst
273+
274+
.. |param| replace:: Option
275+
.. |apiVersion| replace:: ``version``
276+
.. |strict| replace:: ``strict``
277+
.. |deprecation| replace:: ``deprecationErrors``
278+
279+
The ``api`` parameter has the following syntax:
280+
281+
.. code-block:: javascript
282+
283+
{ api: { version: <string>, strict: <boolean>, deprecationErrors: <boolean> } }
284+
285+
Examples
286+
--------
287+
260288
Connect to a MongoDB Cluster
261289
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
262290

@@ -277,8 +305,8 @@ Issue operations against the ``cluster`` object to interact with the
277305

278306
.. _mongo-connection-client-side-encryption-enabled:
279307

280-
Connect to a MongoDB Cluster with Client-Side Encryption Enabled
281-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
308+
Connect to a Cluster with Client-Side Encryption Enabled
309+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282310

283311
Configuring client-side field level encryption for a :ref:`locally
284312
managed key <field-level-encryption-local-kms>` requires specifying a
@@ -338,8 +366,8 @@ a complete list of client-side field level encryption methods.
338366

339367
.. _mongo-connection-automatic-client-side-encryption-enabled:
340368

341-
Connect to a MongoDB Cluster with Automatic Client-Side Encryption Enabled
342-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
369+
Connect to a Cluster with Automatic Client-Side Encryption Enabled
370+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
343371

344372
Configuring client-side field level encryption for a :ref:`locally
345373
managed key <field-level-encryption-local-kms>` requires specifying a
@@ -424,3 +452,23 @@ the specified data encryption key can decrypt the field.
424452

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