refactor and add unit test for mongo expression