Mongodb open connections fix

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