mongoose handling refactored