Skip to content

Commit 35b6de9

Browse files
committed
more docs
1 parent 040b870 commit 35b6de9

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,29 +110,52 @@ to this:
110110
DATABASES = {
111111
"default": {
112112
"ENGINE": "django_mongodb",
113+
"HOST": "mongodb+srv://cluster0.example.mongodb.net",
113114
"NAME": "my_database",
114115
"USER": "my_user",
115116
"PASSWORD": "my_password",
116-
"OPTIONS": {...},
117+
"PORT": 27017,
118+
"OPTIONS": {
119+
# Example:
120+
"retryWrites": "true",
121+
"w": "majority",
122+
"tls": "false",
123+
},
117124
},
118125
}
119126
```
120127

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+
121134
`OPTIONS` is an optional dictionary of parameters that will be passed to
122135
[`MongoClient`](https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html).
123136

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:
126143

127144
```python
128145
import django_mongodb
129146

130-
MONGODB_URI = "mongodb+srv://myDatabaseUser:D1fficultP%40ssw0rd@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"
131148
DATABASES["default"] = django_mongodb.parse_uri(MONGODB_URI)
132149
```
133150

151+
This constructs a `DATABASES` setting equivalent to the first example.
152+
134153
#### `django_mongodb.parse_uri(uri, conn_max_age=0, test=None)`
135154

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+
136159
- Use `conn_max_age` to configure [persistent database connections](
137160
https://docs.djangoproject.com/en/stable/ref/databases/#persistent-database-connections).
138161
- Use `test` to provide a dictionary of [settings for test databases](

0 commit comments

Comments
 (0)