refactor mongodb stub code