conn_pf = pymongo.Connection(ip,27023,slaveOk=True)
The above allows me to close the session using conn_pf.close().
But:
conn_pfname = pymongo.Connection(ip,27023,slaveOk=True).__getattr__(resource+"_pfname").__getattr__("data")
doesn't allow me to close using conn_pfname.close. It says collection types does not have close method. Did I really open session in my second case?
No, you don't need to close PyMongo connections. Leave them open so that PyMongo's connection pooling gives you the most efficient performance:
http://api.mongodb.com/python/current/faq.html#how-does-connection-pooling-work-in-pymongo
Also, the old APIs like "Connection" and "slave_ok" were deleted from PyMongo years ago, please upgrade to the latest version for the most correct and efficient driver. Use MongoClient: