使用Spring Boot查询mongodb的异常

时间:2018-06-20 02:49:22

标签: mongodb spring-boot

我正在尝试使用以下代码查询MongoDB。虽然根据文档看来似乎正确,但是在执行查询时我仍然遇到运行时异常。请让我知道是否有问题。

@Repository
public interface UserRepository extends MongoRepository<User, String> {    
@Query("{'mobileNumber': ?0, 'password': ?1 }")
    User findByLogin(String mobileNumber, String password);

}

例外:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.bson.json.JsonParseException: JSON reader was expecting ':' but found 'password'.] with root cause

org.bson.json.JsonParseException: JSON reader was expecting ':' but found 'password'.
    at org.bson.json.JsonReader.readBsonType(JsonReader.java:132) ~[bson-3.6.3.jar!/:na]
    at org.bson.codecs.DocumentCodec.decode(DocumentCodec.java:149) ~[bson-3.6.3.jar!/:na]
    at org.bson.codecs.DocumentCodec.decode(DocumentCodec.java:45) ~[bson-3.6.3.jar!/:na]
    at org.bson.Document.parse(Document.java:105) ~[bson-3.6.3.jar!/:na]
    at org.bson.Document.parse(Document.java:90) ~[bson-3.6.3.jar!/:na]
    at org.springframework.data.mongodb.core.query.BasicQuery.<init>(BasicQuery.java:67) ~[spring-data-mongodb-2.0.6.RELEASE.jar!/:2.0.6.RELEASE]
    at org.springframework.data.mongodb.repository.query.StringBasedMongoQuery.createQuery(StringBasedMongoQuery.java:136) ~[spring-data-mongodb-2.0.6.RELEASE.jar!/:2.0.6.RELEASE]
    at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(Abstra

0 个答案:

没有答案