I'm using Pymongo to connect to the a read only instance of my MongoDB replica set.
The problem with my code is that sometimes the query goes through, while sometimes, apparently for no reason and with the same code, i get an Authentication failed error
:
pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed', ....}
I don't understand why is this happening, since i'm performing very basic operations and my connection string should be alright.
import pymongo
from pymongo import MongoClient
client = MongoClient('mongodb://root:MY-PASSWORD@MY-IP:27017/?authSource=MY-DB&replicaSet=replicaSetOne')
db = client.marketdata
cursor = db['MYCOL'].find({'unix': {'$gte': 1611874500}})
for document in cursor:
print(document)
Any kind of advice is appreciated.