Mongodb open connections fix

Fixxed the open connections problem by closing the database connection after requiring the collectionNames list.