Updated mongodb query and test cases