You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using a sparse index on the field fieldFoo and to best utilize it, I need to add an extra $exists condition before the $eqone.
When I manually create it via a criteria, the object is fine and working:
but the current spring-data source code is not supporting it:
org.springframework.data.mongodb.InvalidMongoDbApiUsageException:
Due to limitations of the org.bson.Document, you can't add a second 'fieldFoo'
expression specified as 'fieldFoo : 123';
Criteria already contains 'fieldFoo : Document{{$exists=true}}'
It appears to be a combination of the MongoQueryCreator and the AbstractQueryCreator, where combinations are not supported.
Instead of simple a and chain of single conditions:
We do not support the implicit $and form using our Criteria API, however, we should explore how to enable querying the same field multiple times through our query derivation mechanism.
In the meantime, please use String-based @Query where you supply the desired query string yourself.
mp911de
changed the title
Spring data mongodb repository name convention does not support combination including Exists for a field
Support derived queries using the same field multiple times
Jun 10, 2024
Hi,
I am using a sparse index on the field
fieldFoo
and to best utilize it, I need to add an extra$exists
condition before the$eq
one.When I manually create it via a criteria, the object is fine and working:
Now trying to achieve it via a repository method:
or
this workaround syntax appears fine:
but the current
spring-data
source code is not supporting it:It appears to be a combination of the
MongoQueryCreator
and theAbstractQueryCreator
, where combinations are not supported.Instead of simple a
and
chain of single conditions:we would need a capability of multi-conditions:
...
criteria.and("fieldFoo").exists(true).is("123")
...
Was this not added on purpose, or just not perceived as widely used/needed?
The text was updated successfully, but these errors were encountered: