Closing all the cursors from MongoDB queries.
Caching MongoDB connection to be reused during the entire execution.
(This fixes the too many open files error).