@@ -22,6 +22,8 @@ Connect to MongoDB
22
22
:titlesonly:
23
23
:maxdepth: 1
24
24
25
+ /connect/mongoclient
26
+ /connect/connection-targets
25
27
/connect/tls
26
28
/connect/network-compression
27
29
/connect/server-selection
@@ -52,7 +54,35 @@ the relevant values for your MongoDB deployment.
52
54
:language: python
53
55
:copyable: true
54
56
:linenos:
55
- :emphasize-lines: 5-7
57
+ :emphasize-lines: 4-6
58
+
59
+ Connection
60
+ ----------
61
+
62
+ Local Deployment
63
+ ~~~~~~~~~~~~~~~~
64
+
65
+ .. code-block:: python
66
+
67
+ uri = "mongodb://localhost:27017/"
68
+ client = MongoClient(uri)
69
+
70
+ Atlas
71
+ ~~~~~
72
+
73
+ .. code-block:: python
74
+
75
+ uri = "<Atlas connection string>"
76
+ client = MongoClient(uri, server_api=pymongo.server_api.ServerApi(
77
+ version="1", strict=True, deprecation_errors=True))
78
+
79
+ Replica Set
80
+ ~~~~~~~~~~~
81
+
82
+ .. code-block:: python
83
+
84
+ uri = "mongodb://<replica set member>:<port>/?replicaSet=<replica set name>"
85
+ client = MongoClient(uri)
56
86
57
87
Transport Layer Security (TLS)
58
88
------------------------------
@@ -173,7 +203,7 @@ Server Selection
173
203
.. code-block:: python
174
204
175
205
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname>:<port>",
176
- server_selector=<selector function>)
206
+ server_selector=<selector function>)
177
207
178
208
To learn more about customizing server selection, see
179
209
:ref:`pymongo-server-selection`.
@@ -182,12 +212,11 @@ To learn more about customizing server selection, see
182
212
--------------
183
213
184
214
.. code-block:: python
185
- :emphasize-lines: 4
186
215
187
216
from pymongo.server_api import ServerApi
188
217
189
218
client = pymongo.MongoClient("mongodb://<username>:<password>@<hostname:<port>",
190
- server_api=ServerApi("<{+stable-api+} version>"))
219
+ server_api=ServerApi("<{+stable-api+} version>"))
191
220
192
221
To learn more about the {+stable-api+}, see :ref:`pymongo-stable-api`.
193
222
0 commit comments