refactor mongodb