Affects Version/s: 2.2.4 (Moore SR4)
Fix Version/s: 3.0 RC1 (Neumann)
Environment:macOS Catalina, Apache Maven 3.6.2, Java 1.8.0_202, Spring Boot 2.2.4.RELEASE, MongoDB Community Server 4.2.1
I had to build a big QueryDSL predicate to fetch documents. As result, I get an exception; because the depth of the document used by MongoTemplate was greater than the maximum depth limits.
Using Spring Data MongoDB's Criteria I achieved this query with no errors. Criteria's API defines two different operations: and(...) and andOperator(...). QueryDSL has nothing similar to that, but I think we don't need a different operation.
MongodbDocumentSerializer is used to create the final query that eventually will be used by MongoTemplate. This serializer should create documents with the minimum depth as possible.
I actually coded a solution to this (from branch 2.2.x) and tested it. This change removes nested "$or" in "$or" operations, and nested "$and" in "$and" operations, generating just one logical operator. In case of an "$and", this code keeps merging documents with different properties; same way it does now.
How does it work? What do I expect?
Using QueryDSL we can build a predicate like this:
The final document that MongoTemplate will use for querying will be:
What I want to get:
In case of chained ANDs, this may be the result: