Skip to content
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

INTPYTHON-509 add db_name parameter to parse_uri() #249

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timgraham
Copy link
Collaborator

No description provided.

@timgraham
Copy link
Collaborator Author

@R-shubham do you want to ask those who ran into this if the error message makes sense?

django_mongodb_backend/utils.py Outdated Show resolved Hide resolved
@timgraham timgraham changed the title INTPYTHON-509 make parse_uri() raise a helpful message when database name is missing INTPYTHON-509 add db_name parameter to parse_uri() Feb 6, 2025
@timgraham timgraham requested a review from Jibola February 6, 2025 14:29
@timgraham
Copy link
Collaborator Author

Documentation edits (pending #233):

diff --git a/docs/source/ref/utils.rst b/docs/source/ref/utils.rst
index 16a6116..a5fb8ff 100644
--- a/docs/source/ref/utils.rst
+++ b/docs/source/ref/utils.rst
@@ -12,7 +12,7 @@ following parts can be considered stable.
 ``parse_uri()``
 ===============
 
-.. function:: parse_uri(uri, conn_max_age=0, test=None)
+.. function:: parse_uri(uri, db_name=None, conn_max_age=0, test=None)
 
 Parses a MongoDB `connection string`_ into a dictionary suitable for Django's
 :setting:`DATABASES` setting.
@@ -23,8 +23,11 @@ Example::
 
     import django_mongodb_backend
 
-    MONGODB_URI = "mongodb+srv://my_user:[email protected]/myDatabase?retryWrites=true&w=majority&tls=false"
-    DATABASES["default"] = django_mongodb_backend.parse_uri(MONGODB_URI)
+    MONGODB_URI = "mongodb+srv://my_user:[email protected]/defaultauthdb?retryWrites=true&w=majority&tls=false"
+    DATABASES["default"] = django_mongodb_backend.parse_uri(MONGODB_URI, db_name="example")
+
+You must specify ``db_name`` (the :setting:`NAME` of your database) if the URI
+doesn't specify ``defaultauthdb``.
 
 You can use the parameters to customize the resulting :setting:`DATABASES`
 setting:

@timgraham timgraham requested a review from aclark4life February 6, 2025 15:37
Copy link
Collaborator

@aclark4life aclark4life left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants