File tree Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,13 @@ DATABASES = {
121121` OPTIONS ` is an optional dictionary of parameters that will be passed to
122122[ ` MongoClient ` ] ( https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html ) .
123123
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+
124131Congratulations, your project is ready to go!
125132
126133## Notes on Django QuerySets
Original file line number Diff line number Diff line change @@ -28,21 +28,16 @@ def check_django_compatability():
2828
2929def parse (uri ):
3030 uri = parse_uri (uri )
31+ host = None
3132 port = None
3233
3334 if uri ["fqdn" ] is None :
34- # If fqdn is None this is not a SRV URI so extract port from the first
35- # node in nodelist.
36- if "nodelist" in uri and isinstance (uri ["nodelist" ], list ) and len (uri ["nodelist" ]) > 0 :
37- first_node = uri ["nodelist" ][0 ]
38- if (
39- isinstance (first_node , tuple )
40- and len (first_node ) > 1
41- and isinstance (first_node [1 ], int )
42- ):
43- port = first_node [1 ]
35+ # If fqdn is None this is not a SRV URI so extract host and port from
36+ # the first node in nodelist.
37+ host , port = [f"{ node [0 ]} :{ node [1 ]} " for node in uri ["nodelist" ]][0 ].split (":" )
4438 else :
45- # The fqdn is not none so we need to add the mongodb+srv:// prefix to the host.
39+ # The fqdn is not none so we need to add the mongodb+srv:// prefix to
40+ # the host.
4641 host = f"mongodb+srv://{ uri ['fqdn' ]} "
4742
4843 settings_dict = {
You can’t perform that action at this time.
0 commit comments