Skip to content

Commit 7b68ed7

Browse files
committed
Merge remote-tracking branch 'upstream/standardization' into DOCSP-45200-change-streams
2 parents 803678f + 2b72e4c commit 7b68ed7

26 files changed

+2324
-22
lines changed

source/connect.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ Connect to MongoDB
2222
:titlesonly:
2323
:maxdepth: 1
2424

25-
/connect/mongoclient
25+
Create a Client </connect/mongoclient>
26+
Stable API </connect/stable-api>
27+
Choose a Connection Target </connect/connection-targets>

source/connect/connection-targets.txt

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
.. _ruby-connection-targets:
2+
3+
==========================
4+
Choose a Connection Target
5+
==========================
6+
7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. meta::
12+
:keywords: connection string, URI, server, settings, client
13+
14+
.. contents:: On this page
15+
:local:
16+
:backlinks: none
17+
:depth: 2
18+
:class: singlecol
19+
20+
Overview
21+
--------
22+
23+
In this guide, you can learn how to use a connection string and a ``Mongo::Client`` object
24+
to connect to different types of MongoDB deployments.
25+
26+
Atlas
27+
-----
28+
29+
To connect to a MongoDB deployment on Atlas, include the following elements
30+
in your connection string:
31+
32+
- The URL of your Atlas cluster
33+
- Your MongoDB username
34+
- Your MongoDB password
35+
36+
Then, pass your connection string to the ``Mongo::Client`` constructor.
37+
38+
.. tip::
39+
40+
Follow the :atlas:`Atlas driver connection guide </driver-connection>`
41+
to retrieve your connection string.
42+
43+
When you connect to Atlas, we recommend using the {+stable-api+} client option to avoid
44+
breaking changes when Atlas upgrades to a new version of {+mdb-server+}.
45+
To learn more about the {+stable-api+} feature, see the :ref:`<ruby-stable-api>`
46+
guide.
47+
48+
The following code shows how to use the {+driver-short+} to connect to an Atlas cluster. The
49+
code also uses the ``server_api`` field to specify a {+stable-api+} version.
50+
51+
.. literalinclude:: /includes/connect/connection-targets.rb
52+
:language: ruby
53+
:start-after: start-connection-target-atlas
54+
:end-before: end-connection-target-atlas
55+
:dedent:
56+
57+
Local Deployments
58+
-----------------
59+
60+
To connect to a local standalone MongoDB deployment, specify the host of the
61+
server. Optionally, specify the port of the server and the database to connect
62+
to. If no port is specified, the default port is ``27017``. If no database name
63+
is specified, the client will use the ``admin`` database:
64+
65+
.. literalinclude:: /includes/connect/connection-targets.rb
66+
:language: ruby
67+
:start-after: start-local-connection
68+
:end-before: end-local-connection
69+
:dedent:
70+
71+
You can also specify the host, port, and database to connect to using a
72+
connection string:
73+
74+
.. literalinclude:: /includes/connect/connection-targets.rb
75+
:language: ruby
76+
:start-after: start-local-connection-uri
77+
:end-before: end-local-connection-uri
78+
:dedent:
79+
80+
You can also specify your host as ``localhost``. The following code example
81+
connects to ``localhost`` on the default port, ``27017``:
82+
83+
.. literalinclude:: /includes/connect/connection-targets.rb
84+
:language: ruby
85+
:start-after: start-localhost
86+
:end-before: end-localhost
87+
:dedent:
88+
89+
Replica Sets
90+
------------
91+
92+
To connect to a replica set, it is recommended to specify all nodes that are
93+
part of the replica set. In the event that one or more nodes becomes unavailable,
94+
specifying all nodes allows the driver to still connect to the replica set,
95+
as long as one node is available.
96+
97+
However, it is sufficient to pass the address of any one node in the replica set
98+
to the driver. The node does not have to be the primary, and it may be a hidden node.
99+
The driver will then automatically discover the remaining nodes.
100+
101+
The following example shows how to specify three members of the replica set:
102+
103+
.. literalinclude:: /includes/connect/connection-targets.rb
104+
:language: ruby
105+
:start-after: start-replica-set
106+
:end-before: end-replica-set
107+
:dedent:
108+
109+
The following example shows how to connect to the replica set using a connection
110+
string:
111+
112+
.. literalinclude:: /includes/connect/connection-targets.rb
113+
:language: ruby
114+
:start-after: start-replica-set-uri
115+
:end-before: end-replica-set-uri
116+
:dedent:
117+
118+
The following example shows how to verify the replica set name upon connection
119+
by using the ``replica_set`` option or the ``replicaSet`` connection string option:
120+
121+
.. literalinclude:: /includes/connect/connection-targets.rb
122+
:language: ruby
123+
:start-after: start-replica-set-option
124+
:end-before: end-replica-set-option
125+
:dedent:
126+
127+
API Documentation
128+
-----------------
129+
130+
To learn more about creating a ``Mongo::Client`` object with the {+driver-short+},
131+
see the API documentation for `Mongo::Client <{+api-root+}/Mongo/Client.html>`__ .

source/connect/stable-api.txt

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
.. _ruby-stable-api:
2+
3+
===========
4+
Stable API
5+
===========
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:keywords: compatible, backwards, upgrade
19+
20+
.. note::
21+
22+
The Stable API feature requires {+mdb-server+} 5.0 or later.
23+
24+
Overview
25+
--------
26+
27+
In this guide, you can learn how to specify **{+stable-api+}** compatibility when
28+
connecting to a MongoDB deployment.
29+
30+
The {+stable-api+} feature forces the server to run operations with behaviors compatible
31+
with the API version you specify. Using the {+stable-api+} ensures consistent responses
32+
from the server and provides long-term API stability for your application.
33+
34+
The following sections describe how you can enable and customize the {+stable-api+} for
35+
your MongoDB client. For more information about the {+stable-api+}, including a list of
36+
the commands it supports, see :manual:`Stable API </reference/stable-api/>` in the
37+
{+mdb-server+} manual.
38+
39+
Enable the {+stable-api+}
40+
-------------------------
41+
42+
To enable the {+stable-api+}, pass a hash that specifies the {+stable-api+} version to the optional
43+
``server_api`` parameter when you create a ``Mongo::Client`` instance.
44+
45+
The following code example shows how to specify {+stable-api+} version 1:
46+
47+
.. code-block:: ruby
48+
49+
client = Mongo::Client.new(uri, server_api: { version: '1' })
50+
51+
Once you create a ``Client`` instance with
52+
a specified API version, all commands that you run with the client use the specified
53+
version. If you must run commands using more than one version of the
54+
{+stable-api+}, create a new ``Client``.
55+
56+
Configure the {+stable-api+}
57+
----------------------------
58+
59+
The following table describes {+stable-api+} options that you can set by specifying
60+
them in the ``server_api`` hash. You can use these options to customize the behavior of the
61+
{+stable-api+}.
62+
63+
.. list-table::
64+
:header-rows: 1
65+
:stub-columns: 1
66+
:widths: 25,75
67+
68+
* - Option Name
69+
- Description
70+
71+
* - strict
72+
- | **Optional**. When ``true``, if you call a command that isn't part of
73+
the declared API version, the driver raises an exception.
74+
|
75+
| Default: **false**
76+
77+
* - deprecation_errors
78+
- | **Optional**. When ``true``, if you call a command that is deprecated in the
79+
declared API version, the driver raises an exception.
80+
|
81+
| Default: **false**
82+
83+
The following code example shows how you can set the two options on a ``ServerApi`` instance:
84+
85+
.. code-block:: ruby
86+
87+
client = Mongo::Client.new(uri,
88+
server_api: { version: '1', strict: true, deprecation_errors: true })
89+
90+
Troubleshooting
91+
---------------
92+
93+
The following sections describe common issues you might encounter when using the {+stable-api+}.
94+
95+
Unrecognized field 'apiVersion' on server
96+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97+
98+
The {+driver-short+} raises this exception if you specify an API version and connect to a
99+
MongoDB server that doesn't support the {+stable-api+}. Ensure you're connecting to a
100+
deployment running {+mdb-server+} v5.0 or later.
101+
102+
Provided apiStrict:true, but the command count is not in API Version
103+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104+
105+
The {+driver-short+} raises this exception if your ``Client`` runs an operation that
106+
isn't in the {+stable-api+} version you specified. To avoid this error, use an alternative
107+
operation supported by the specified {+stable-api+} version, or set the ``strict``
108+
option to ``false`` when constructing your ``ServerApi`` object.
109+
110+
API Documentation
111+
-----------------
112+
113+
For more information about using the {+stable-api+} with the {+driver-short+}, see the
114+
following API documentation:
115+
116+
- `Mongo::Client <{+api-root+}/Mongo/Client.html>`__

source/data-formats.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. _ruby-data-formats:
2+
3+
============
4+
Data Formats
5+
============
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:description: Learn how to use indexes by using the MongoDB Ruby Driver.
19+
:keywords: ruby, query, collections, time series
20+
21+
.. toctree::
22+
:titlesonly:
23+
:maxdepth: 1
24+
25+
Time Series Data </data-formats/time-series>
26+
27+
Overview
28+
--------
29+
30+
You can use several types of specialized data formats in your {+driver-short+}
31+
application. To learn how to work with these data formats, see the following
32+
sections:
33+
34+
- :ref:`ruby-time-series`: Learn how to create a time series collection and interact with time series data.

0 commit comments

Comments
 (0)