Writing data to mongoDB