Make mongodb connection safe mode  & more logging

Make mongodb connection wait for writes to finish using safe mode