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
103103
104104### Configuring the ` DATABASES ` setting
105105
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:
108115
109116``` python
110117DATABASES = {
@@ -121,13 +128,6 @@ DATABASES = {
121128` OPTIONS ` is an optional dictionary of parameters that will be passed to
122129[ ` MongoClient ` ] ( https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html ) .
123130
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-
131131Congratulations, your project is ready to go!
132132
133133## Notes on Django QuerySets
Original file line number Diff line number Diff line change @@ -36,10 +36,10 @@ def parse(uri, **kwargs):
3636 # If the fqdn is present, this is a SRV URI and the host is the fqdn.
3737 host = f"mongodb+srv://{ uri ['fqdn' ]} "
3838 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" ] )
4343
4444 settings_dict = {
4545 "ENGINE" : "django_mongodb" ,
You can’t perform that action at this time.
0 commit comments