File tree Expand file tree Collapse file tree 2 files changed +13
-13
lines changed Expand file tree Collapse file tree 2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -103,8 +103,15 @@ $ python manage.py startapp myapp --template https://github.com/mongodb-labs/dja
103
103
104
104
### Configuring the ` DATABASES ` setting
105
105
106
- After you've set up a project, configure Django's ` DATABASES ` setting similar
107
- to this:
106
+ After you've set up a project, configure Django's ` DATABASES ` with
107
+ ` django_mongodb.parse(uri) ` :
108
+
109
+ ``` python
110
+ MONGODB_URI = " mongodb://<my_user>:<my_password>@localhost:27017/my_database"
111
+ DATABASES [" default" ] = django_mongodb.parse(MONGODB_URI )
112
+ ```
113
+
114
+ Alternatively, you can configure the DATABASES settings directly:
108
115
109
116
``` python
110
117
DATABASES = {
@@ -121,13 +128,6 @@ DATABASES = {
121
128
` OPTIONS ` is an optional dictionary of parameters that will be passed to
122
129
[ ` MongoClient ` ] ( https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html ) .
123
130
124
- Alternatively, you can use a MongoDB URI with ` django_mongodb.parse(uri) ` :
125
-
126
- ``` python
127
- MONGODB_URI = " mongodb://<my_user>:<my_password>@localhost:27017/my_database"
128
- DATABASES [" default" ] = django_mongodb.parse(MONGODB_URI )
129
- ```
130
-
131
131
Congratulations, your project is ready to go!
132
132
133
133
## Notes on Django QuerySets
Original file line number Diff line number Diff line change @@ -36,10 +36,10 @@ def parse(uri, **kwargs):
36
36
# If the fqdn is present, this is a SRV URI and the host is the fqdn.
37
37
host = f"mongodb+srv://{ uri ['fqdn' ]} "
38
38
else :
39
- # If the fqdn is not present, this is a standard URI and the host and
40
- # port are in the nodelist.
41
- nodelist = [ f" { node [ 0 ] } : { node [ 1 ] } " for node in uri [ "nodelist" ]]
42
- host , port = nodelist [ 0 ]. split ( ":" )
39
+ if len ( uri ( "nodelist" )) == 1 :
40
+ host , port = uri ( " nodelist" )[ 0 ]. split ( ":" )
41
+ elif len ( uri ( "nodelist" )) > 1 :
42
+ host = "," . join ( uri [ "nodelist" ] )
43
43
44
44
settings_dict = {
45
45
"ENGINE" : "django_mongodb" ,
You can’t perform that action at this time.
0 commit comments