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
This commit is contained in:
committed by
Mark Paluch
parent
cee6092292
commit
bfa479108a
@@ -719,7 +719,7 @@ public class QueryMapper {
|
||||
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)));
|
||||
|
||||
@@ -1684,6 +1684,18 @@ public class QueryMapperUnitTests {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user