Saving data to mongodb. Handling exceptions. Shutdown