How many connections will open in mongodb in python?
Question: I am working with mongodb and python, for accessing the database I am doing
this:

    
    
    #pymongo connection settings
    from pymongo import Connection
    connection = Connection('localhost', 27017)
    db = connection['MyDB']
    

I am inserting documents like this:

    
    
    db_data = db.mycollection.insert({'name': 'Mulagala', 'age': 24})
    

and finding like this:

    
    
    db_data = db.mycollection.find()
    

When I am creating multiple users or getting `mycollection` details for
multiple times how many conections will open in mongodb. Do I need to close
any open connection before returning result?


Answer: No matter how many `db.coll.find({...})` and `db.coll.insert({...})` will you
do, you will still have only one connection. You do not need to close open
connection (at the end of the script it will be closed automatically)

**P.S.** `MongoClient` is the preferred method to [connect to
mongo](https://api.mongodb.org/python/current/tutorial.html) (`Connection` is
deprecated)

