Skip to content

Commit b9162d1

Browse files
authored
DOCSP-18071: fix connection guide (#499)
* DOCSP-18071: fix node connection guide * first pass fixes * MW & CC PR fixes 1
1 parent 8bbec4a commit b9162d1

File tree

5 files changed

+50
-31
lines changed

5 files changed

+50
-31
lines changed

source/code-snippets/connection/srv.js renamed to source/code-snippets/connection/connect.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const { MongoClient } = require("mongodb");
22

33
// Connection URI
4-
const uri =
5-
"mongodb+srv://sample-hostname:27017/?maxPoolSize=20&w=majority";
4+
const uri = "<connection string uri>";
65

76
// Create a new MongoClient
87
const client = new MongoClient(uri);

source/fundamentals/connection/connect.txt

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
Connection Guide
55
================
66

7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
713
This guide shows you how to connect to a MongoDB instance or replica set
814
using the Node.js driver.
915

@@ -18,19 +24,20 @@ example shows each part of the connection URI:
1824
.. figure:: /includes/figures/connection-string-parts.png
1925
:alt: Each part of the connection string
2026

21-
In this example, for the protocol, we use ``mongodb+srv`` which specifies the
22-
:manual:`DNS Seedlist Connection Format
23-
</reference/connection-string/#dns-seedlist-connection-format>`. This indicates
24-
that the hostname following it corresponds to the DNS SRV record of your
25-
MongoDB instance or deployment. If your instance or deployment does not have a
26-
DNS SRV record, use ``mongodb`` to specify the :manual:`Standard Connection
27-
Format </reference/connection-string/#standard-connection-string-format>`.
27+
In this example, we use ``mongodb`` for the protocol, which specifies
28+
the :manual:`Standard Connection String Format </reference/connection-string/#std-label-connections-standard-connection-string-format>`.
29+
30+
If your instance or deployment has a DNS SRV record, you can use the
31+
:manual:`DNS Seed List Connection Format
32+
</reference/connection-string/#dns-seed-list-connection-format>` for
33+
your connection string. This format offers more flexibility of
34+
deployment and the ability to change the servers in rotation without
35+
reconfiguring clients.
2836

2937
.. note::
3038

31-
If your deployment is on MongoDB Atlas, follow the
32-
:atlas:`Atlas driver connection guide </driver-connection?tck=docs_driver_nodejs>`
33-
to retrieve your connection string.
39+
To learn how to retrieve your connection string in Atlas, see the
40+
:atlas:`Atlas driver connection guide </driver-connection>`.
3441

3542
The next part of the connection string contains your username and password
3643
if you are using password-based authentication. Replace the value of ``user``
@@ -39,7 +46,7 @@ authentication mechanism that does not require a username and password, omit
3946
this part of the connection URI.
4047

4148
The next part of the connection string specifies the hostname or IP address and
42-
port of your MongoDB instance. In the example above, we use ``sample-hostname``
49+
port of your MongoDB instance. In the example above, we use ``sample.host``
4350
as the hostname and ``27017`` as the port. Replace these values to point to
4451
your MongoDB instance.
4552

@@ -48,12 +55,12 @@ options as parameters. In the example above, we set two connection options:
4855
``maxPoolSize=20`` and ``w=majority``. For more information on connection
4956
options, skip to the :ref:`node-connection-options` section.
5057

51-
.. _connect-atlas-node-driver:
58+
.. _connect-sample-node-driver:
5259

53-
The code below shows how you can use the sample connection URI in a client to
60+
The code below shows how you can use a connection URI in a client to
5461
connect to MongoDB.
5562

56-
.. literalinclude:: /code-snippets/connection/srv.js
63+
.. literalinclude:: /code-snippets/connection/connect.js
5764
:language: javascript
5865

5966
.. _node-other-ways-to-connect:
@@ -71,7 +78,7 @@ Connect to a MongoDB Server on Your Local Machine
7178
.. include:: /includes/localhost-connection.rst
7279

7380
To test whether you can connect to your server, replace the connection
74-
string in the :ref:`Connect to MongoDB Atlas <connect-atlas-node-driver>` code
81+
string in the :ref:`Connect to MongoDB <connect-sample-node-driver>` code
7582
example and run it.
7683

7784
Connect to a Replica Set
@@ -94,10 +101,10 @@ When making a connection, the driver takes the following actions by default:
94101
- Discovers all replica set members when given the address of any one member.
95102
- Dispatches operations to the appropriate member, such as write against the **primary**.
96103

97-
.. tip::
104+
.. tip:: Specify all hosts
98105

99-
You only need to specify one host to connect to a replica set. However, to ensure connectivity if the specified host
100-
is unavailable, provide the full list of hosts.
106+
To ensure connectivity if one host is unavailable, provide the full
107+
list of hosts when connecting to a replica set.
101108

102109
Direct Connection
103110
^^^^^^^^^^^^^^^^^
@@ -109,7 +116,7 @@ driver does not accept the DNS seedlist connection format (SRV) when you
109116
specify this option.
110117

111118
When you specify ``directConnection`` and connect to a secondary member of the
112-
replica set, your write operations fail because it is not the primary member.
113-
To perform read operations, you must enable secondary reads. See the
114-
:manual:`read preference options </reference/connection-string/#read-preference-options>`
119+
replica set, your write operations fail because the client isn't
120+
connected to the primary member. To perform read operations, you must
121+
enable secondary reads. See the :manual:`read preference options </reference/connection-string/#read-preference-options>`
115122
for more information.

source/fundamentals/connection/connection-options.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ parameters of the connection URI to specify the behavior of the client.
5555
* - **connectTimeoutMS**
5656
- non-negative integer
5757
- ``10000``
58-
- Specifies the amount of time to wait to establish a single TCP
58+
- Specifies the amount of time, in milliseconds, to wait to establish a single TCP
5959
socket connection to the server before raising an error. Specifying
6060
``0`` disables the connection timeout.
6161

@@ -68,7 +68,7 @@ parameters of the connection URI to specify the behavior of the client.
6868
* - **heartbeatFrequencyMS**
6969
- integer greater than or equal to 500
7070
- ``null``
71-
- Specifies the interval between regular server monitoring checks.
71+
- Specifies the interval, in milliseconds, between regular server monitoring checks.
7272

7373
* - **journal**
7474
- boolean
@@ -84,14 +84,14 @@ parameters of the connection URI to specify the behavior of the client.
8484
* - **localThresholdMS**
8585
- non-negative integer
8686
- ``15``
87-
- Specifies the size of the latency window on round trip time for
87+
- Specifies the size of the latency window, in milliseconds, on round trip time for
8888
selecting between suitable servers. Specifying ``0`` means no wait,
8989
meaning the fastest available server.
9090

9191
* - **maxIdleTimeMS**
9292
- non-negative integer
9393
- ``0``
94-
- Specifies the amount of time a connection can be idle before it's closed.
94+
- Specifies the amount of time, in milliseconds, a connection can be idle before it's closed.
9595
Specifying ``0`` means no minimum.
9696

9797
* - **maxPoolSize**
@@ -196,7 +196,7 @@ parameters of the connection URI to specify the behavior of the client.
196196
* - **socketTimeoutMS**
197197
- non-negative integer
198198
- ``0``
199-
- Specifies the amount of time spent attempting to send or receive on a
199+
- Specifies the amount of time, in milliseconds, spent attempting to send or receive on a
200200
socket before timing out. Specifying ``0`` means no timeout.
201201

202202
* - **srvMaxHosts**
@@ -216,6 +216,11 @@ parameters of the connection URI to specify the behavior of the client.
216216
- ``false``
217217
- The ``ssl`` is an alias for the ``tls`` option.
218218

219+
* - **timeoutMS**
220+
- non-negative integer
221+
- unset (feature is not enabled by default)
222+
- Specifies the timeout, in milliseconds, for the full execution of an operation.
223+
219224
* - **tls**
220225
- boolean
221226
- ``false``
@@ -280,7 +285,7 @@ parameters of the connection URI to specify the behavior of the client.
280285
* - **waitQueueTimeoutMS**
281286
- non-negative integer
282287
- ``0``
283-
- Specifies the amount of time spent attempting to check out a connection
288+
- Specifies the amount of time, in milliseconds, spent attempting to check out a connection
284289
from a server's connection pool before timing out.
285290

286291
* - **wTimeoutMS**

source/includes/localhost-connection.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ purposes instead of using an Atlas cluster, you need to complete the following:
1818
After you successfully start your MongoDB server, specify your connection
1919
string in your driver connection code.
2020

21-
If your MongoDB Server is running locally, you can use the connection string
22-
``"mongodb://localhost:<port>"`` where ``<port>`` is the port number you
21+
If your MongoDB Server is running locally, you can use the following
22+
connection string:
23+
24+
.. code-block:: none
25+
26+
mongodb://localhost:<port>
27+
28+
In this connection string, ``<port>`` is the port number on which you
2329
configured your server to listen for incoming connections.
2430

2531
If you need to specify a different hostname or IP address, see our Server

source/quick-start.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ This command performs the following actions:
7979
At this point, you are ready to use the {+driver-short+} with your
8080
application.
8181

82+
.. _node-quickstart-connect-cluster:
83+
8284
Create a MongoDB Cluster
8385
~~~~~~~~~~~~~~~~~~~~~~~~
8486

0 commit comments

Comments
 (0)