Code
client = pymongo.MongoClient("mongodb srv://username:[email protected]/db?retryWrites=true&w=majority&ssl=true&ssl_cert_reqs=CERT_NONE")
db = client["db"]
#this gives the error
res = list(db.listings.find({}).limit(15).sort([('$natural',-1)]))
Error:
pymongo.errors.ServerSelectionTimeoutError: No replica set members found yet
I get this error in the line where I assign the variable res
.
And I don't get this error when run it on my machine, but when i run it on a server i get the error.
CodePudding user response:
This type of error is usually:
- Not using the latest
pymongo
drivers (https://pypi.org/project/pymongo/ list the current latest version) - Not having the
dnspython
module installed (I had issues 2.1.0 so would recommend 2.0.0)
CodePudding user response:
I tried every solution in these answers but the only thing that worked is just
using the flask_pymongo
module instead of pymongo
. And now i don't get any errors.