PIM-2328: Refactor mongo query