PyMongo pymongo.errors.ServerSelectionTimeoutError while using find_one()/insert() but not find()

Viewed 445

I have a replica set of 3 mongo_dbs on kubernetes. I have a flask api which is routing and connecting fine and returning results with find_one.

I have another container which is a py script that is querying the same db which is not working.

Info Python 3.8.5 Pymongo==3.11.0

here is my code

client = MongoClient('mongodb://mongo-0.mongo,mongo-1.mongo,mongo-2.mongo')
mydb = client["test"]
mycol = mydb["test"]
last_products = mycol.find()

returns <pymongo.cursor.Cursor object at XXXX>

client = MongoClient('mongodb://mongo-0.mongo,mongo-1.mongo,mongo-2.mongo')
mydb = client["test"]
mycol = mydb["test"]
mydic = {"keywords":"test"}
x = mycol.insert(mydic)

returns

pymongo.errors.ServerSelectionTimeoutError: mongo-2.mongo:27017: timed out,mongo-1.mongo:27017: timed out,mongo-0.mongo:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 5f68ab8ca324912b2a836a19, topology_type: Unknown, servers: [<ServerDescription ('mongo-0.mongo', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('mongo-0.mongo:27017: timed out')>, <ServerDescription ('mongo-1.mongo', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('mongo-1.mongo:27017: timed out')>, <ServerDescription ('mongo-2.mongo', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('mongo-2.mongo:27017: timed out')>]>

When I exec into the container/pod of the primary of the replica set I get this rs0:PRIMARY> db.test.findOne() { "_id" : ObjectId("5f67b89c5463336d74dc4a4c"), "keyword" : "test" }

I have no idea how to really troubleshoot this further. Has anyone came across this issue or have any suggestions?

Thanks in advance

0 Answers
Related