MongoDB Database Init function

Moved MongoDB Database Connection Code to a separate function.