creating mongodb connection, handling events