Closed mohamed-elsabagh closed 6 years ago
Sorry, I have no experience with Atlas and probably this is not the right place to raise this ticket. Djongo is for connecting with a MongoDB instance with Django.
Hi, I recently used Djongo with MongoDB Atlas in PythonAnywhere and found the solution. I don't know if this is a good practice or not; I just followed the error trail.
Do pip install dnspython
.
Open this file:
yourvirtualenvfolder/lib/python3.6/site-packages/pymongo/mongo_client.py
Search for this part of code:
class MongoClient(common.BaseObject):
HOST = "localhost"
PORT = 27017
Substitute "localhost"
with your SRV address, for example:
class MongoClient(common.BaseObject):
HOST = "mongodb+srv://dnsServerName/test"
PORT = 27017
Save the file, and voila, you're connected to MongoDB Atlas. You don't need to change anything else in settings.py except for djongo database settings.
Hope this helps :)
Sorry, I have no experience with Atlas and probably this is not the right place to raise this ticket. Djongo is for connecting with a MongoDB instance with Django.
This is about how to connect to MongoDB to a remote server. MongoAtlas is just a service provider for mongo DB. I can't find anywhere about how to connect to DB using connection URI.
Do we have provision to connect to DB using URI? If not, having that would be great.
Hi, I recently used Djongo with MongoDB Atlas in PythonAnywhere and found the solution. I don't know if this is a good practice or not; I just followed the error trail.
- Do
pip install dnspython
.- Open this file:
yourvirtualenvfolder/lib/python3.6/site-packages/pymongo/mongo_client.py
- Search for this part of code:
class MongoClient(common.BaseObject): HOST = "localhost" PORT = 27017
- Substitute
"localhost"
with your SRV address, for example:class MongoClient(common.BaseObject): HOST = "mongodb+srv://dnsServerName/test" PORT = 27017
Save the file, and voila, you're connected to MongoDB Atlas. You don't need to change anything else in settings.py except for djongo database settings.
Hope this helps :)
I only needed to run this to make it work:
pip3 install dnspython
pip install djongo pip install dnspython
in settings.py
DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'dbname', 'HOST': 'mongodb+srv://username:password@cluster0-4oblc.gcp.mongodb.net/test?ssl=true&ssl_cert_reqs=CERT_NONE&retryWrites=true', } }
./manage.py makemigrations ./manage.py migrate
Why is this closed? It is still a bug with djongo 1.3.0
I am having the exact same issue. I can even connect to the dockerized mongo container by executing an interactive bash from the app container, and pointing it to the dockerized mongo URI, but django fails to connect returning an error of No mongodb hosts found
Let me ellaborate:
print(host)
in venv/lib/python3.6/site-packages/pymongo/mongo_client.py
after changing the host
to the mongo URIlocalhsot
venv/lib/python3.6/site-packages/djongo/base.py
line 176 I've also added a print(name)
and the method get_new_connection
never seems to be called.webapp/webapp/settings.py
I have in HOST' : 'mongodb://segnetmongo:27017'
which always times-out and returns a No mongodb hosts found
mongo mongodb://segnetmongo:27017/
I get a connection just fine.I've tried to follow the rabbit down the hole to see why get_new_connection
is not called, and I know that pymongo
(assuming that's the connection handler for djongo) expects a host
parameter, else it defaults to localhost
(which it does). What I don't understand is why is the MongoClient
constructor isn't not receiving the HOST
parameter from the settings.py
file.
Hi, I recently used Djongo with MongoDB Atlas in PythonAnywhere and found the solution. I don't know if this is a good practice or not; I just followed the error trail.
- Do
pip install dnspython
.- Open this file:
yourvirtualenvfolder/lib/python3.6/site-packages/pymongo/mongo_client.py
- Search for this part of code:
class MongoClient(common.BaseObject): HOST = "localhost" PORT = 27017
- Substitute
"localhost"
with your SRV address, for example:class MongoClient(common.BaseObject): HOST = "mongodb+srv://dnsServerName/test" PORT = 27017
Save the file, and voila, you're connected to MongoDB Atlas. You don't need to change anything else in settings.py except for djongo database settings.
Hope this helps :)
This works in my case when using a shared Cluster on Mongo Atlas. Thanks.
Hi, I recently used Djongo with MongoDB Atlas in PythonAnywhere and found the solution. I don't know if this is a good practice or not; I just followed the error trail.
- Do
pip install dnspython
.- Open this file:
yourvirtualenvfolder/lib/python3.6/site-packages/pymongo/mongo_client.py
- Search for this part of code:
class MongoClient(common.BaseObject): HOST = "localhost" PORT = 27017
- Substitute
"localhost"
with your SRV address, for example:class MongoClient(common.BaseObject): HOST = "mongodb+srv://dnsServerName/test" PORT = 27017
Save the file, and voila, you're connected to MongoDB Atlas. You don't need to change anything else in settings.py except for djongo database settings. Hope this helps :)
This works in my case when using a shared Cluster on Mongo Atlas. Thanks.
You say that you've got it working with a shared cluster in mongo atlas. I've got my app set up that way too. I'm on version 1.3.2 of djongo. Did you get an error like this?
Applying contenttypes.0001_initial...This version of djongo does not support "schema validation using CONSTRAINT" fully. Visit https://www.patreon.com/nesdis
Traceback (most recent call last):
File "/home/user/proc/.venv/lib/python3.6/site-packages/djongo/sql2mongo/query.py", line 842, in parse
return handler(self, statement)
File "/home/user/proc/.venv/lib/python3.6/site-packages/djongo/sql2mongo/query.py", line 907, in _insert
query = InsertQuery(self, self.db, self.connection_properties, sm, self._params)
File "/home/user/proc/.venv/lib/python3.6/site-packages/djongo/sql2mongo/query.py", line 339, in __init__
super().__init__(*args)
File "/home/user/proc/.venv/lib/python3.6/site-packages/djongo/sql2mongo/query.py", line 61, in __init__
self.parse()
File "/home/user/proc/.venv/lib/python3.6/site-packages/djongo/sql2mongo/query.py", line 409, in parse
self._fill_values(statement)
File "/home/user/proc/.venv/lib/python3.6/site-packages/djongo/sql2mongo/query.py", line 367, in _fill_values
raise SQLDecodeError
djongo.exceptions.SQLDecodeError
Is there any proper fix available for this?
python3.6
Hi @irpl I fix the same issue when I install sqlparse==0.2.4, give a try.
@irpl this will fail when you deploy your application to hosting platforms like heroku or Azure, during build itself, it will override the changes in mongo_client.py
@agiokas-dbg @gustavofleury @noelpuru Pretty sure you're encountering this documentation issue: https://github.com/nesdis/djongo/issues/410#issuecomment-646885842
@jie8357IOII Thanks for that hint! I was receiving DatabaseErrors when running migrate, but ignored that little red line warning about djongo requiring sqlparse===0.2.4 during pip install. It was installing v0.3.1 for some reason, but downgrading it made the migrate command work.
Hi, I recently used Djongo with MongoDB Atlas in PythonAnywhere and found the solution. I don't know if this is a good practice or not; I just followed the error trail.
- Do
pip install dnspython
.- Open this file:
yourvirtualenvfolder/lib/python3.6/site-packages/pymongo/mongo_client.py
- Search for this part of code:
class MongoClient(common.BaseObject): HOST = "localhost" PORT = 27017
- Substitute
"localhost"
with your SRV address, for example:class MongoClient(common.BaseObject): HOST = "mongodb+srv://dnsServerName/test" PORT = 27017
Save the file, and voila, you're connected to MongoDB Atlas. You don't need to change anything else in settings.py except for djongo database settings. Hope this helps :)
This works in my case when using a shared Cluster on Mongo Atlas. Thanks.
this one solved my problem and for my settings.py
DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'ebookstore', 'HOST': ', 'USER': '', 'PASSWORD': '', } }
sqlparse==0.2.4
This solved the issue, just installed sqlparse==0.2.4 into my virtual env. Thanks brother!
Hi everyone, I solved the problem with the following steps: settings.py: DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'db_name', 'CLIENT': { 'host': 'mongodb+srv://your_db_user>:<your_db_password>@cluster0.zhs7q.mongodb.net/<db_name?retryWrites=true&w=majority', 'username': 'your_db_user', 'password': 'your_db_password', }, } }
and then if you get error like this: [SSL: CERTIFICATE_VERIFY_FAILED]
you can follow this: https://stackoverflow.com/questions/52805115/certificate-verify-failed-unable-to-get-local-issuer-certificate
I resolved this issue with the following steps:
pip install djongo
(i suppose this is already done)pip install dnspython
settings.py
# import
from pymongo.mongo_client import MongoClient
DATABASES = {
'default': {
'ENGINE': "djongo",
'NAME':
MongoClient.HOST = "mongodb+srv://
>Django==3.0.5
>djongo==1.3.3
>dnspython==2.0.0
>Atlas: MongoDB Version 4.2.10
I resolved this issue with the following steps:
pip install djongo
(i suppose this is already done)pip install dnspython
- edits in
settings.py
# import from pymongo.mongo_client import MongoClient # replace default DATABASES dictionary DATABASES = { 'default': { 'ENGINE': "djongo", 'NAME': <dbname>, } } # copy connection string provided by atlas only upto dns name # i.e exclude: "<dbname>?retryWrites=true&w=majority" # following is my case MongoClient.HOST = "mongodb+srv://<username>:<password>@mongodb.vsega.mongodb.net/" # replace <placeholder(s)> with your credentials (obvio)
Django==3.0.5 djongo==1.3.3 dnspython==2.0.0 Atlas: MongoDB Version 4.2.10
this is really helpful
pip install djongo pip install dnspython
in settings.py
DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'dbname', 'HOST': 'mongodb+srv://username:password@cluster0-4oblc.gcp.mongodb.net/test?ssl=true&ssl_cert_reqs=CERT_NONE&retryWrites=true', } }
./manage.py makemigrations ./manage.py migrate
Thanks a lot this worked for me
I am trying to connect my django application to my remote Mongodb replica set running on Atlas, how can this be done in the configuration in the settings.py how can I fill the configuration for the following dns for example
mongo "mongodb+srv://dnsServerName/test" --username myusername
I have tried several configuration but it gives me timeout error although my ip address is white listed and I can connect to the DB from my machine