Skip to content

Commit f3d7145

Browse files
authored
DOCSP-47875: Add new parse_uri parameter (#26)
1 parent de6d4d7 commit f3d7145

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

source/connect.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ your MongoDB connection, you can use the ``parse_uri()`` function. This
145145
function accepts the following arguments:
146146

147147
- ``uri``: Your MongoDB connection URI.
148+
- ``db_name``: The name of the database you want to use.
148149
- ``conn_max_age``: Configures persistent database connections.
149150
This argument is optional. To learn more, see
150151
`Persistent connections <{+django-docs+}/ref/databases/#persistent-database-connections>`__
@@ -165,8 +166,8 @@ example:
165166

166167
import django_mongodb_backend
167168

168-
MONGODB_URI = "mongodb+srv://my_user:[email protected]/my_database?retryWrites=true&w=majority"
169-
DATABASES["default"] = django_mongodb_backend.parse_uri(MONGODB_URI)
169+
MONGODB_URI = "mongodb+srv://my_user:[email protected]/?retryWrites=true&w=majority"
170+
DATABASES["default"] = django_mongodb_backend.parse_uri(MONGODB_URI, db_name="<database name>")
170171

171172
Additional Information
172173
----------------------

source/get-started/connect-mongodb.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ you can create a {+framework+} project that connects to MongoDB.
6464
.. code-block:: python
6565

6666
DATABASES = {
67-
"default": django_mongodb_backend.parse_uri("<connection string URI>"),
67+
"default": django_mongodb_backend.parse_uri("<connection string URI>", db_name="<database name>"),
6868
}
6969

7070
Replace the ``<connection string URI>`` placeholder with the connection string

source/get-started/connection-string.txt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,5 @@ when applicable, and connection options.
5454
Replace the ``<db_username>`` and ``<db_password>`` placeholders with
5555
your database user's username and password.
5656

57-
.. step:: Add a database to your connection string
58-
59-
Specify a database connection in your connection string by adding
60-
your database name after the hostname, as shown in the following example:
61-
62-
.. code-block:: none
63-
:copyable: false
64-
65-
mongodb+srv://<db_username>:<db_password>@samplecluster.ojeyz.mongodb.net/<database name>?retryWrites=true&w=majority&appName=SampleCluster
66-
67-
Replace the ``<database name>`` placeholder with ``sample_mflix`` to
68-
configure a connection to the ``sample_mflix`` Atlas sample database.
69-
7057
After completing these steps, you have a connection string that
7158
contains your database username, database password, and database name.

0 commit comments

Comments
 (0)