@@ -105,8 +105,21 @@ to match the first two numbers from your version.)
105105Configuring the ``DATABASES `` setting
106106=====================================
107107
108- After you've set up a project, configure Django's :setting: `DATABASES ` setting
109- similar to this::
108+ After you've set up a project, configure Django's :setting: `DATABASES ` setting.
109+
110+ If you have a connection string, you can provide it like this::
111+
112+ DATABASES = {
113+ "default": {
114+ "ENGINE": "django_mongodb_backend",
115+ "HOST": "mongodb+srv://my_user:my_password@cluster0.example.mongodb.net/myDatabase?retryWrites=true&w=majority&tls=false",
116+ "NAME": "my_database",
117+ },
118+ }
119+
120+ Alternatively, you can separate the connection string so that your settings
121+ look more like what you usually see with Django. This constructs a
122+ :setting: `DATABASES ` setting equivalent to the first example::
110123
111124 DATABASES = {
112125 "default": {
@@ -117,7 +130,6 @@ similar to this::
117130 "PASSWORD": "my_password",
118131 "PORT": 27017,
119132 "OPTIONS": {
120- # Example:
121133 "retryWrites": "true",
122134 "w": "majority",
123135 "tls": "false",
@@ -128,8 +140,8 @@ similar to this::
128140For a localhost configuration, you can omit :setting: `HOST ` or specify
129141``"HOST": "localhost" ``.
130142
131- :setting: ` HOST ` only needs a scheme prefix for SRV connections
132- (`` mongodb+srv:// ``). A `` mongodb:// `` prefix is never required .
143+ If you provide a connection string in `` HOST ``, any of the other values below
144+ will override the values in the connection string .
133145
134146:setting: `OPTIONS ` is an optional dictionary of parameters that will be passed
135147to :class: `~pymongo.mongo_client.MongoClient `.
@@ -143,17 +155,6 @@ For a replica set or sharded cluster where you have multiple hosts, include
143155all of them in :setting: `HOST `, e.g.
144156``"mongodb://mongos0.example.com:27017,mongos1.example.com:27017" ``.
145157
146- Alternatively, if you prefer to simply paste in a MongoDB URI rather than parse
147- it into the format above, you can use
148- :func: `~django_mongodb_backend.utils.parse_uri `::
149-
150- import django_mongodb_backend
151-
152- MONGODB_URI = "mongodb+srv://my_user:my_password@cluster0.example.mongodb.net/myDatabase?retryWrites=true&w=majority&tls=false"
153- DATABASES["default"] = django_mongodb_backend.parse_uri(MONGODB_URI)
154-
155- This constructs a :setting: `DATABASES ` setting equivalent to the first example.
156-
157158.. _configuring-database-routers-setting :
158159
159160Configuring the ``DATABASE_ROUTERS `` setting
0 commit comments