Client connection in Pymongo

1.1k Views Asked by At

How does MongoClient works and creates a connection pooling or thread creation?

What are major resources used if a create a multiple connections?

My main reson for asking is this ? I have created multiple classes in python which represents functionality of single collection in mongodb. In each class i am creating a client

 self.client = MongoClient(hostname, port)

What resources i need to worry about and what can be performance issues?

If there way i can share single client along all classes ?

1

There are 1 best solutions below

1
On

Make one MongoClient. Make it a global variable in a module:

client = MongoClient(host, port)

A MongoClient has a built-in connection pool, and it starts a thread to monitor its connection to your server. For best efficiency, make one MongoClient and share it throughout your program.