Predicate With Multiple Conditions On The Same Field Fails #442
I'm seeing some strange behavior when trying to AND multiple fields with the same name - the last one in wins, and it's because of the use of a LinkedHashMap in MongodbSerializer.
My expectation: startsWithIgnoreCase(somefield, startValue) && endsWithIgnoreCase(somefield, endValue) should result in a mongo query that includes both restrictions.
The reality: startsWithIgnoreCase(somefield, startValue) && endsWithIgnoreCase(somefield, endValue) results in a mongo query with only the last restriction on somefield.
Is my expectation incorrect? Is there another way to achieve this query? Or is this a defect?
Suppose you have a predicate whose String representation is:
...and you create a MongodbQuery and invoke MongodbQuery.where(predicate). Then you invoke list() on the query.
MongodbQuery.list() calls MongodbQuery.createCursor() which in turn leverages MongodbSerializer.handle(predicate) - source.
The String representation of the where value in QueryMetadata is:
As the expression is processed by handle, visit(Operation<?> expr, Void context) (source) is hit. Visit leverages BasicDBObject (extends BasicBSONObject, extends LinkedHashMap <String, Object>) for the AND scenario. As the expression is processed, the conditions are put in this structure: here. Because this is not a multi-value HashMap, if multiple conditions exist for the same key, then only the last one will end up in the resulting BasicDBObject.
Consequently, information is lost in the serialization of the expression to the MongoDB query.
The text was updated successfully, but these errors were encountered:
I've run my tests against the 3.2.1 SNAPSHOT build (https://oss.sonatype.org/content/repositories/snapshots/com/mysema/querydsl/querydsl-mongodb/3.2.1.BUILD-SNAPSHOT/) and your commits have addressed the issue I reported.
Any ETA on a release that would include this? Thanks for your help!!