Implemented writing to mongodb