refactored mongodb insertion in factory class