I am trying to connect Monogdb to my flask application. But I keep getting this connection error.
This is the error I keep getting:
pymongo.errors.ServerSelectionTimeoutError: csmongodb:27018: [Errno 111] Connection refused
Below are the details:
import pymongo
client = pymongo.MongoClient(app.config['MONGODB_URI'],tls=MONGODB_USE_TLS,tlsAllowInvalidCertificates=True)
database = client.test_db
client.drop_database(test_db)
The MONOGODB_URI format I followed is following:
mongodb://{user}:{pwd}@{host}:{port}/{db}
My docker compose file is something like this:
csmongodb:
container_name: "cs_mongodb_1"
image: "mongo:3.6-xenial"
env_file:
- ".env"
volumes:
- csmongodb:/data/db
ports:
- "27018:27018"
command: mongod --smallfiles --logpath=/dev/null # --quiet
networks:
- "backend"
I am using pymongo version 3.9.0
question from:
https://stackoverflow.com/questions/66048205/pymongo-returns-connection-refused 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…