I\'m using:
First set up the MongoDB environment.
Run this on CMD - "C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe"
And then you can use pymongo [anaconda prompt]
import pymongo
from pymongo import MongoClient
client = MongoClient()
db = client.test_db
collection = db['test_coll']
Refer - https://docs.mongodb.com/tutorials/install-mongodb-on-windows/
I am not sure if you are using the MongoDB paired with AWS Cloud service. But if you are, I found that you have to specify which IP Address you want MongoDB to have access to.
So what you need to do is add the IP Address of your host server to allow entry.
In MongoAtlas, this can be done at this page
I know there was already a solution to the same issue, but I didn't find a solution that helped my situation, so wanted to post this, so others could benefit if they ever face the same problem that I do.
I've come accross the same problem and finally I found that the client IP is blocked by the firewall of the mongo server.
maybe you can try to add your server ip address into the mongod.conf file. if you use linux(ubuntu) os,you can try my solution:
modify mongod.conf file:
vi /etc/mongod.conf
and you can add mongodb server ip address behind 127.0.0.1,and save:
net:
port:27017
bindIp:127.0.0.1,mongodb server ip
in the teminal:
sudo service mongod restart
Now,you can try to connect mongodb by using pymongo MongoClient.
This has been fixed in PyMongo
with this pull_request.
I fixed it for myself by downgrading from pymongo 3.0 to 2.8. No idea what's going on.
flask/bin/pip uninstall pymongo
flask/bin/pip install pymongo==2.8