Skip to content

Commit

Permalink
Fixed in arrays issue
Browse files Browse the repository at this point in the history
  • Loading branch information
agiannone committed Jun 23, 2023
1 parent f20f3cb commit cfab6c0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ private boolean checkMatch(Object queryValue, List<String> keys, Object value) {
Object allQuery = query.get(QueryOperator.ALL.getValue());
return checkMatchesAllDocuments(allQuery, keys, value);
}
if (query.containsKey(QueryOperator.NOT_EQUALS.getValue())) {
Object notEqualQuery = query.get(QueryOperator.NOT_EQUALS.getValue());
return !checkMatchesAnyDocument(notEqualQuery, keys, value);
}
if (query.containsKey(QueryOperator.NOT_IN.getValue())) {
Object notInQueryValue = query.get(QueryOperator.NOT_IN.getValue());
Document inQuery = new Document(QueryOperator.IN.getValue(), notInQueryValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,18 @@ void testMatchesNotEqual() throws Exception {
assertThat(matcher.matches(document, query)).isTrue();
}

// https://github.com/bwaldvogel/mongo-java-server/issues/220
@Test
void testMatchesNeFieldInArray() throws Exception {
Document query = json("'tags.value': {$ne: 'B'}");

Document document = json("_id: 1, tags: [{'value': 'A'}, {'value': 'D'}]");
assertThat(matcher.matches(document, query)).isTrue();

document = json("_id: 1, tags: [{'value': 'B'}, {'value': 'A'}]");
assertThat(matcher.matches(document, query)).isFalse();
}

// http://docs.mongodb.org/v3.0/reference/operator/query/eq/#op._S_eq
@Test
void testMatchesEqual() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2307,6 +2307,19 @@ void testMatchesNinFieldInArray() throws Exception {
.containsExactly(json("_id: 1, tags: [{'value': 'A'}, {'value': 'D'}]"));
}

// https://github.com/bwaldvogel/mongo-java-server/issues/220
@Test
void testMatchesNeFieldInArray() throws Exception {
collection.insertOne(json("_id: 1, tags: [{'value': 'A'}, {'value': 'D'}]"));
collection.insertOne(json("_id: 2, tags: [{'value': 'A'}, {'value': 'B'}]"));
collection.insertOne(json("_id: 3, tags: [{'value': 'A'}, {'value': 'C'}]"));

assertThat(collection.find(json("'tags.value': {$ne: 'B'}")))
.containsExactly(
json("_id: 1, tags: [{'value': 'A'}, {'value': 'D'}]"),
json("_id: 3, tags: [{'value': 'A'}, {'value': 'C'}]"));
}

// https://github.com/bwaldvogel/mongo-java-server/issues/7
@Test
void testMatchesNotIn() throws Exception {
Expand Down

0 comments on commit cfab6c0

Please sign in to comment.