0

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.