Skip to content

Commit 3b69e3e

Browse files
committed
feedback
1 parent 9a9220b commit 3b69e3e

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

source/configure-connection.txt

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ After installing {+django-odm+} and creating a project, you can configure
3030
your connection to MongoDB in the following ways:
3131

3232
- :ref:`django-connection-configure-manual` by specifying the
33-
``DATABASES`` variable in your project's settings
33+
``DATABASES`` variable in your project's settings.
3434
- :ref:`django-connection-configure-automatic` by using
35-
the ``parse_uri()`` method
35+
the ``parse_uri()`` method.
3636

3737
.. tip::
3838

@@ -47,9 +47,15 @@ Manually Configure Database Settings
4747
To manually configure your connection to MongoDB, update
4848
the ``DATABASES`` variable in your project's ``settings.py``
4949
file. Set the ``DATABASES`` variable to a dictionary value containing
50-
the database settings. You must configure the dictionary's
51-
``default`` key to set MongoDB as the default database
52-
connection.
50+
the ``default`` key, as shown in the following example:
51+
52+
.. code-block:: python
53+
54+
DATABASES = {
55+
"default": {
56+
# Specify nested dictionary keys here
57+
},
58+
}
5359

5460
To configure the ``default`` key, assign a nested dictionary as its value.
5561
This nested dictionary has the following keys:
@@ -68,37 +74,46 @@ This nested dictionary has the following keys:
6874
- | Your connection URI. For localhost connections, this key is optional.
6975
| For SRV connections, you must include a scheme prefix (``mongodb+srv://``).
7076
|
71-
| If connecting to a replica set or sharded cluster with multiple hosts, specify
72-
| each host separated by a comma.
77+
| To specify more than one host, include all hostnames in one string. Use
78+
| a comma to separate each hostname, as shown in the following example:
79+
80+
.. code-block:: python
81+
82+
"HOST": "mongodb://mongos0.example.com:27017,mongos1.example.com:27017"
7383

7484
* - **NAME**
7585
- The database you want to use.
7686

7787
* - **USER**
78-
- The username for authenticating to the database.
88+
- The username for authenticating to the database, if your connection
89+
requires authentication.
7990

8091
* - **PASSWORD**
81-
- The password for your database user.
92+
- The password for your database user, if your connection requires authentication.
8293

8394
* - **PORT**
84-
- | The port number on which the database server is listening.
95+
- | The port number on which the database server is listening. The default
96+
port is ``27017``.
8597
| For MongoDB Atlas connections, this key is optional.
8698

8799
* - **OPTIONS**
88-
- A dictionary of additional connection options for the database. This key is optional.
100+
- | A dictionary of additional connection options for the database. This key is optional.
101+
| To see a full list of connection options that you can set in the ``OPTIONS`` key,
102+
see the optional parameters for `MongoClient <https://pymongo.readthedocs.io/en/4.10.1/api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient>`__
103+
in the PyMongo API documentation.
89104

90105
.. _django-manual-config-example:
91106

92107
Example
93108
```````
94109

95-
This example specifies the ``DATABASES`` variable to connect
96-
to a MongoDB deployment with the following configuration:
110+
In this example, the ``DATABASES`` variable specifies the
111+
following connection configuration:
97112

98-
- Connects to the ``my_database`` database
113+
- Sets the database to ``my_database``
99114
- Provides authentication information for a database user
100115
whose username is ``my_user`` and password is ``my_password``
101-
- Uses the default MongoDB port (``27017``)
116+
- Specifies the default MongoDB port (``27017``)
102117
- Sets the ``retryWrites`` connection option to ``true``,
103118
which configures the driver to automatically retry certain
104119
write operations if they fail
@@ -123,13 +138,6 @@ to a MongoDB deployment with the following configuration:
123138
},
124139
}
125140

126-
.. tip::
127-
128-
To see a full list of connection options that you
129-
can set in the ``OPTIONS`` key, see the optional
130-
parameters for `MongoClient <https://pymongo.readthedocs.io/en/4.10.1/api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient>`__
131-
in the PyMongo API documentation.
132-
133141
.. _django-connection-configure-automatic:
134142

135143
Automatically Configure Database Settings
@@ -152,9 +160,8 @@ method accepts the following arguments:
152160
Example
153161
```````
154162

155-
The following example uses the ``parse_uri()`` method to connect
156-
to a MongoDB deployment with the same configuration as
157-
the previous :ref:`manual configuration <django-manual-config-example>`
163+
The following example uses the ``parse_uri()`` method to specify
164+
the same connection configuration as the previous :ref:`manual configuration <django-manual-config-example>`
158165
example:
159166

160167
.. code-block:: python

0 commit comments

Comments
 (0)