Skip to content

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

Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions source/configure-connection.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand All @@ -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:
Expand All @@ -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**
Copy link

Choose a reason for hiding this comment

The 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

View workflow job for this annotation

GitHub Actions / TDBX Vale rules

[vale] reported by reviewdog 🐶 [MongoDB.ConciseTerms] 'more' is preferred over 'additional'. Raw Output: {"message": "[MongoDB.ConciseTerms] 'more' is preferred over 'additional'.", "location": {"path": "source/configure-connection.txt", "range": {"start": {"line": 97, "column": 26}}}, "severity": "ERROR"}
| 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``,
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 DATABASES variable performs the
following steps:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading