Skip to content

Commit

Permalink
Fix id mapping when using $all operator.
Browse files Browse the repository at this point in the history
Fix the id mapping for queries using the $all operator. Prior to this change the collection nature of the id values was not preserved leading to an invalid query.

Original pull request: #4742
Closes #4736
  • Loading branch information
christophstrobl authored and mp911de committed Aug 30, 2024
1 parent cee6092 commit bfa4791
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ private Object convertIdField(Field documentField, Object source) {
for (Entry<String, Object> entry : valueDbo.entrySet()) {

String key = entry.getKey();
if ("$nin".equals(key) || "$in".equals(key)) {
if ("$nin".equals(key) || "$in".equals(key) || "$all".equals(key)) {
List<Object> ids = new ArrayList<>();
for (Object id : (Iterable<?>) valueDbo.get(key)) {
ids.add(convertId(id, getIdTypeForField(documentField)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,18 @@ void convertsNestedOperatorValueForPropertyContainingListThatHasValueConverter()
assertThat(mappedObject).isEqualTo("{ 'text' : { $gt : 'gnirps', $in : [ 'atad' ] } }");
}

@Test // GH-4736
void allOperatorShouldConvertIdCollection() {

ObjectId oid = ObjectId.get();
Criteria criteria = new Criteria().andOperator(where("name").isNull().and("id").all(List.of(oid.toString())));

org.bson.Document mappedObject = mapper.getMappedObject(criteria.getCriteriaObject(),
context.getPersistentEntity(Customer.class));

assertThat(mappedObject).containsEntry("$and.[0]._id.$all", List.of(oid));
}

class WithSimpleMap {
Map<String, String> simpleMap;
}
Expand Down

0 comments on commit bfa4791

Please sign in to comment.