-
Notifications
You must be signed in to change notification settings - Fork 20
DOCSP-46328: Django connection configuration #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
e35be75
445573a
49b6d69
5500f74
9a9220b
3b69e3e
f935192
1049049
11d4f2c
90b7c58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,9 @@ | |
your connection to MongoDB in the following ways: | ||
|
||
- :ref:`django-connection-configure-manual` by specifying the | ||
``DATABASES`` variable in your project's settings | ||
``DATABASES`` variable in your project's settings. | ||
- :ref:`django-connection-configure-automatic` by using | ||
the ``parse_uri()`` method | ||
the ``parse_uri()`` method. | ||
|
||
.. tip:: | ||
|
||
|
@@ -47,9 +47,15 @@ | |
To manually configure your connection to MongoDB, update | ||
the ``DATABASES`` variable in your project's ``settings.py`` | ||
file. Set the ``DATABASES`` variable to a dictionary value containing | ||
the database settings. You must configure the dictionary's | ||
``default`` key to set MongoDB as the default database | ||
connection. | ||
the ``default`` key, as shown in the following example: | ||
|
||
.. code-block:: python | ||
|
||
DATABASES = { | ||
"default": { | ||
# Specify nested dictionary keys here | ||
}, | ||
} | ||
|
||
To configure the ``default`` key, assign a nested dictionary as its value. | ||
This nested dictionary has the following keys: | ||
|
@@ -68,37 +74,43 @@ | |
- | Your connection URI. For localhost connections, this key is optional. | ||
| For SRV connections, you must include a scheme prefix (``mongodb+srv://``). | ||
| | ||
| If connecting to a replica set or sharded cluster with multiple hosts, specify | ||
| each host separated by a comma. | ||
| To specify more than one host, include all hostnames in one string. Use | ||
a comma to separate each hostname. | ||
| **Example:** ``"HOST": "mongodb://mongos0.example.com:27017,mongos1.example.com:27017"`` | ||
|
||
* - **NAME** | ||
- The database you want to use. | ||
|
||
* - **USER** | ||
- The username for authenticating to the database. | ||
- The username for authenticating to the database, if your connection | ||
requires authentication. | ||
|
||
* - **PASSWORD** | ||
- The password for your database user. | ||
- The password for your database user, if your connection requires authentication. | ||
|
||
* - **PORT** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you can say the default port is 27017 |
||
- | The port number on which the database server is listening. | ||
- | The port number on which the database server is listening. The default | ||
port is ``27017``. | ||
| For MongoDB Atlas connections, this key is optional. | ||
|
||
* - **OPTIONS** | ||
- A dictionary of additional connection options for the database. This key is optional. | ||
- | A dictionary of additional connection options for the database. This key is optional. | ||
Check failure on line 97 in source/configure-connection.txt
|
||
| To see a full list of connection options that you can set in the ``OPTIONS`` key, | ||
see the optional parameters for `MongoClient <https://pymongo.readthedocs.io/en/4.10.1/api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient>`__ | ||
in the PyMongo API documentation. | ||
|
||
.. _django-manual-config-example: | ||
|
||
Example | ||
``````` | ||
|
||
This example specifies the ``DATABASES`` variable to connect | ||
to a MongoDB deployment with the following configuration: | ||
In this example, the ``DATABASES`` variable specifies the | ||
following connection configuration: | ||
|
||
- Connects to the ``my_database`` database | ||
- Sets the database to ``my_database`` | ||
- Provides authentication information for a database user | ||
whose username is ``my_user`` and password is ``my_password`` | ||
- Uses the default MongoDB port (``27017``) | ||
- Specifies the default MongoDB port (``27017``) | ||
- Sets the ``retryWrites`` connection option to ``true``, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i: there's a double verb here--'specifies' in the paragraph and then 'connects'/'sets' in the list items. i can't add a suggestion in GH, but maybe something like this: In this example, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed to just "...performs the following actions" |
||
which configures the driver to automatically retry certain | ||
write operations if they fail | ||
|
@@ -123,13 +135,6 @@ | |
}, | ||
} | ||
|
||
.. tip:: | ||
|
||
To see a full list of connection options that you | ||
can set in the ``OPTIONS`` key, see the optional | ||
parameters for `MongoClient <https://pymongo.readthedocs.io/en/4.10.1/api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient>`__ | ||
in the PyMongo API documentation. | ||
|
||
.. _django-connection-configure-automatic: | ||
|
||
Automatically Configure Database Settings | ||
|
@@ -152,9 +157,8 @@ | |
Example | ||
``````` | ||
|
||
The following example uses the ``parse_uri()`` method to connect | ||
to a MongoDB deployment with the same configuration as | ||
the previous :ref:`manual configuration <django-manual-config-example>` | ||
The following example uses the ``parse_uri()`` method to specify | ||
the same connection configuration as the previous :ref:`manual configuration <django-manual-config-example>` | ||
example: | ||
|
||
.. code-block:: python | ||
|
Uh oh!
There was an error while loading. Please reload this page.