Skip to content

$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

@kareldh

Description

@kareldh

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']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions