Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$nin on field of object in array returns documents if any object in the array matches the $nin instead of all objects matching the $nin #215

Closed
kareldh opened this issue Feb 1, 2023 · 2 comments

Comments

@kareldh
Copy link

kareldh commented Feb 1, 2023

When filtering on a specific field of the objects within an array with $nin, I expect a document to match if no object in the array has that field matching the $nin. But currently, if any object within the array has that field not matching the $nin, the document is returned.
This behaviour differs from e.g. CosmosDb.

Example

@Test
    void testMatchesNinFieldInArray() throws Exception {
        Document query = json("{'tags.value': {$nin: ['B', 'C']}}");

        assertThat(matcher.matches(json("tags: [{'value': 'A'}, {'value': 'D'}]"), query)).isTrue();
        assertThat(matcher.matches(json("tags: [{'value': 'A'}, {'value': 'B'}]"), query)).isFalse();
        assertThat(matcher.matches(json("tags: [{'value': 'A'}, {'value': 'C'}]"), query)).isFalse();
    }

When filtering for documents where the tags array doesn't contain a tag with value B or C, I expect only the first document to be returend, but the second and third document are also returned because they contain {'value': 'A'} which matches $nin: [ 'B', 'C']

@kareldh kareldh changed the title $nin on field of object in array returns documents where that field does match a value from the array $nin on field of object in array returns documents if any object in the array matches the $nin instead of all objects matching the $nin Feb 1, 2023
@bwaldvogel
Copy link
Owner

Thanks for reporting this issue. It should be fixed with 73b7dff

@bwaldvogel
Copy link
Owner

The fix is available fix v1.44.0

rgruber1 pushed a commit to rgruber1/mongo-java-server that referenced this issue Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants