I'm trying to execute an expression that returns a set of results where the collection attribute is not empty. Here are my classes
A.class
@Document
public class A {
@Id String id;
String name;
List<B> matches;
}
B.class
@Document
public class B {
String name;
}
My test case
@Test
public void testFindWhereCollectionNotEmpty() {
B b1 = new B();
b1.name = "b1";
B b2 = new B();
b2.name = "b2";
template.save(b1);
template.save(b2);
A a1 = new A();
a1.id = "p1";
a1.matches = Arrays.asList(b1, b2);
A a2 = new A();
a2.id = "a2";
a2.matches = new ArrayList<B>();
A a3 = new A();
a3.id = "a3";
a3.matches = null;
template.save(a1);
template.save(a2);
template.save(a3);
QA qa = QA.a;
BooleanExpression expr = qa.matches.isNotEmpty();
Iterable<A> result = aRepo.findAll(expr);
assertThat(result, is(not((emptyIterable()))));
}
When I execute this test I get the following error:
com.mongodb.MongoException: Can't canonicalize query: BadValue $or needs an array
at com.mongodb.QueryResultIterator.throwOnQueryFailure(QueryResultIterator.java:214)
at com.mongodb.QueryResultIterator.init(QueryResultIterator.java:198)
at com.mongodb.QueryResultIterator.initFromQueryResponse(QueryResultIterator.java:176)
at com.mongodb.QueryResultIterator.<init>(QueryResultIterator.java:64)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:86)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:66)
at com.mongodb.DBCursor._check(DBCursor.java:458)
at com.mongodb.DBCursor._hasNext(DBCursor.java:546)
at com.mongodb.DBCursor.hasNext(DBCursor.java:571)
at com.mysema.query.mongodb.MongodbQuery.list(MongodbQuery.java:253)
at org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.findAll(QueryDslMongoRepository.java:102)
You can try this for yourself at https://github.com/tedp/spring-querydsl-test
Am I doing something wrong?
This issue has now been fixed in version 3.6.3 of QueryDSL. See https://github.com/querydsl/querydsl/issues/1264 for further info.
Many thanks to all those who were involved in the fix!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With