Reputation: 2195
I'm using MongoDB with Spring Data. This query works:
@Query("{ 'user.token' : ?0 }")
List<Event> findByUserKey(String userKey);
But this query does not work and throws "java.lang.String cannot be cast to com.mongodb.DBObject":
@Query("'$or':[ { 'user.token' : ?0 } , { 'user.id' : ?0 } ]")
List<Event> findByUserKey(String userKey);
I think the query is well written, any idea? Thanks.
Upvotes: 0
Views: 1516
Reputation: 75934
Query takes a document. Add the parenthesis around the query string.
@Query("{'$or':[ { 'user.token' : ?0 } , { 'user.id' : ?0 } ]}")
List<Event> findByUserKey(String userKey);
You will need spring boot 1.5.2 / spring mongo 1.10.1 version for the placeholder to resolve correctly.
https://jira.spring.io/browse/DATAMONGO-1603
Upvotes: 1