@@ -110,29 +110,52 @@ to this:
110
110
DATABASES = {
111
111
" default" : {
112
112
" ENGINE" : " django_mongodb" ,
113
+ " HOST" : " mongodb+srv://cluster0.example.mongodb.net" ,
113
114
" NAME" : " my_database" ,
114
115
" USER" : " my_user" ,
115
116
" PASSWORD" : " my_password" ,
116
- " OPTIONS" : {... },
117
+ " PORT" : 27017 ,
118
+ " OPTIONS" : {
119
+ # Example:
120
+ " retryWrites" : " true" ,
121
+ " w" : " majority" ,
122
+ " tls" : " false" ,
123
+ },
117
124
},
118
125
}
119
126
```
120
127
128
+ For a local host configuration, you can omit ` "HOST" ` or specify
129
+ ` "HOST": "localhost" ` .
130
+
131
+ Depending on your configuration, ` HOST ` , ` USER ` , ` PASSWORD ` , ` PORT ` , and
132
+ ` OPTIONS ` may be optional.
133
+
121
134
` OPTIONS ` is an optional dictionary of parameters that will be passed to
122
135
[ ` MongoClient ` ] ( https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html ) .
123
136
124
- Alternatively, if you prefer to simply paste in a MongoDB URI rather than
125
- parsing it into the format above, you can use:
137
+ For a replica set or sharded cluster where you have multiple hosts, include
138
+ all of them in ` "HOST" ` , e.g.
139
+ ` "mongodb://mongos0.example.com:27017,mongos1.example.com:27017" ` .
140
+
141
+ Alternatively, if you prefer to simply paste in a MongoDB URI rather than parse
142
+ it into the format above, you can use:
126
143
127
144
``` python
128
145
import django_mongodb
129
146
130
- MONGODB_URI = " mongodb+srv://myDatabaseUser:D1fficultP %40s sw0rd @cluster0.example.mongodb.net/myDatabase?retryWrites=true&w=majority&tls=false"
147
+ MONGODB_URI = " mongodb+srv://my_user:my_password @cluster0.example.mongodb.net/myDatabase?retryWrites=true&w=majority&tls=false"
131
148
DATABASES [" default" ] = django_mongodb.parse_uri(MONGODB_URI )
132
149
```
133
150
151
+ This constructs a ` DATABASES ` setting equivalent to the first example.
152
+
134
153
#### ` django_mongodb.parse_uri(uri, conn_max_age=0, test=None) `
135
154
155
+ ` parse_uri() ` provides a few options to customize the resulting ` DATABASES `
156
+ setting, but for maximum flexibility, construct ` DATABASES ` manually as
157
+ described above.
158
+
136
159
- Use ` conn_max_age ` to configure [ persistent database connections] (
137
160
https://docs.djangoproject.com/en/stable/ref/databases/#persistent-database-connections ).
138
161
- Use ` test ` to provide a dictionary of [ settings for test databases] (
0 commit comments