@@ -47,33 +47,44 @@ Manually Configure Database Settings
47
47
To manually configure your connection to MongoDB, update
48
48
the ``DATABASES`` setting in your project's ``settings.py``
49
49
file. The ``DATABASES`` setting has a ``default`` key,
50
- which you must specify to set MongoDB as the default database
50
+ which you must configure to set MongoDB as the default database
51
51
connection.
52
52
53
- To specify the ``default`` key, include the following
54
- information :
53
+ To configure the ``default`` key, include the following
54
+ fields :
55
55
56
- - ``ENGINE``: The backend driver to use for the connection.
57
- Set this field to ``"django_mongodb_backend"``.
56
+ .. list-table::
57
+ :header-rows: 1
58
+ :widths: 20 80
58
59
59
- - ``HOST``: Your connection URI. For localhost connections,
60
- this field is optional. For SRV connections, you must include
61
- a scheme prefix (``mongodb+srv://``).
60
+ * - Field
61
+ - Description
62
62
63
- If connecting to a replica set or sharded cluster with multiple hosts, specify
64
- each host separated by a comma .
63
+ * - **ENGINE**
64
+ - The backend driver to use for the connection. Set this field to ``"django_mongodb_backend"`` .
65
65
66
- - ``NAME``: The database you want to use.
66
+ * - **HOST**
67
+ - | Your connection URI. For localhost connections, this field is optional.
68
+ | For SRV connections, you must include a scheme prefix (``mongodb+srv://``).
69
+ |
70
+ | If connecting to a replica set or sharded cluster with multiple hosts, specify
71
+ | each host separated by a comma.
67
72
68
- - ``USER``: The username for authenticating to the database.
73
+ * - **NAME**
74
+ - The database you want to use.
69
75
70
- - ``PASSWORD``: The password for your database user.
76
+ * - **USER**
77
+ - The username for authenticating to the database.
71
78
72
- - ``PORT``: The port number on which the database server is listening.
73
- For MongoDB Atlas connections, this field is optional .
79
+ * - **PASSWORD**
80
+ - The password for your database user .
74
81
75
- - ``OPTIONS``: A dictionary of additional connection options for the database.
76
- This field is optional.
82
+ * - **PORT**
83
+ - | The port number on which the database server is listening.
84
+ | For MongoDB Atlas connections, this field is optional.
85
+
86
+ * - **OPTIONS**
87
+ - A dictionary of additional connection options for the database. This field is optional.
77
88
78
89
.. _django-manual-config-example:
79
90
@@ -83,8 +94,8 @@ Example
83
94
This example specifies the ``DATABASES`` setting to connect
84
95
to a MongoDB deployment with the following configuration:
85
96
86
- - Connects to the ``sample_db `` database
87
- - Provides authentication information for a user
97
+ - Connects to the ``my_database `` database
98
+ - Provides authentication information for a database user
88
99
whose username is ``my_user`` and password is ``my_password``
89
100
- Uses the default MongoDB port (``27017``)
90
101
- Sets the ``retryWrites`` connection option to ``true``,
@@ -125,15 +136,15 @@ Automatically Configure Database Settings
125
136
126
137
To automatically construct the ``DATABASES`` setting that configures
127
138
your MongoDB connection, you can use the ``parse_uri()`` method. This
128
- method accepts the following parameters :
139
+ method accepts the following arguments :
129
140
130
141
- ``uri``: Your MongoDB connection URI.
131
142
- ``conn_max_age``: Configures persistent database connections.
132
- This parameter is optional. To learn more, see
143
+ This argument is optional. To learn more, see
133
144
`Persistent connections <https://docs.djangoproject.com/en/stable/ref/databases/#persistent-database-connections>`__
134
145
in the Django documentation.
135
146
- ``test``: Provides a dictionary of settings for test
136
- databases. This parameter is optional. To learn more, see
147
+ databases. This argument is optional. To learn more, see
137
148
`the TEST setting <https://docs.djangoproject.com/en/stable/ref/settings/#test>`__
138
149
in the Django documentation.
139
150
@@ -149,7 +160,7 @@ example:
149
160
150
161
import django_mongodb_backend
151
162
152
- MONGODB_URI = "mongodb+srv://my_user:
[email protected] /
myDatabase ?retryWrites=true&w=majority"
163
+ MONGODB_URI = "mongodb+srv://my_user:
[email protected] /
my_database ?retryWrites=true&w=majority"
153
164
DATABASES["default"] = django_mongodb_backend.parse_uri(MONGODB_URI)
154
165
155
166
Additional Information
0 commit comments