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 = {
121
121
` OPTIONS ` is an optional dictionary of parameters that will be passed to
122
122
[ ` MongoClient ` ] ( https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html ) .
123
123
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
+
124
131
Congratulations, your project is ready to go!
125
132
126
133
## Notes on Django QuerySets
Original file line number Diff line number Diff line change @@ -28,21 +28,16 @@ def check_django_compatability():
28
28
29
29
def parse (uri ):
30
30
uri = parse_uri (uri )
31
+ host = None
31
32
port = None
32
33
33
34
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 (":" )
44
38
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.
46
41
host = f"mongodb+srv://{ uri ['fqdn' ]} "
47
42
48
43
settings_dict = {
You can’t perform that action at this time.
0 commit comments