Skip to content

Commit d04e76f

Browse files
christophstroblmp911de
authored andcommitted
Fix id mapping when using $all operator.
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
1 parent ffca3db commit d04e76f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ private Object convertIdField(Field documentField, Object source) {
719719
for (Entry<String, Object> entry : valueDbo.entrySet()) {
720720

721721
String key = entry.getKey();
722-
if ("$nin".equals(key) || "$in".equals(key)) {
722+
if ("$nin".equals(key) || "$in".equals(key) || "$all".equals(key)) {
723723
List<Object> ids = new ArrayList<>();
724724
for (Object id : (Iterable<?>) valueDbo.get(key)) {
725725
ids.add(convertId(id, getIdTypeForField(documentField)));

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java

+12
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,18 @@ void convertsNestedOperatorValueForPropertyContainingListThatHasValueConverter()
16841684
assertThat(mappedObject).isEqualTo("{ 'text' : { $gt : 'gnirps', $in : [ 'atad' ] } }");
16851685
}
16861686

1687+
@Test // GH-4736
1688+
void allOperatorShouldConvertIdCollection() {
1689+
1690+
ObjectId oid = ObjectId.get();
1691+
Criteria criteria = new Criteria().andOperator(where("name").isNull().and("id").all(List.of(oid.toString())));
1692+
1693+
org.bson.Document mappedObject = mapper.getMappedObject(criteria.getCriteriaObject(),
1694+
context.getPersistentEntity(Customer.class));
1695+
1696+
assertThat(mappedObject).containsEntry("$and.[0]._id.$all", List.of(oid));
1697+
}
1698+
16871699
class WithSimpleMap {
16881700
Map<String, String> simpleMap;
16891701
}

0 commit comments

Comments
 (0)