在mongorepository中使用'and'和'or'进行查询

时间:2019-11-12 07:47:56

标签: mongodb spring-boot select

我有一个查询要选择: 条件是: isPublic = true和(partnerID(例如“ CS%”)或partnerID(例如“ CL%”))

我在下面写了一个查询:

@Query("{ isPublic: true, $or: [ { partnerID: /^CS/ }, { partnerID: /^CL/ } ] }")
    List<Partner> findCSPublic();

但是有错误并非如此:

2019-11-12 14:40:48.191  WARN 10368 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'partnerController': Unsatisfied dependency expressed through field 'parterService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'partnerServiceImp': Unsatisfied dependency expressed through field 'partnerRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'partnerRepository': Invocation of init method failed; nested exception is com.mongodb.util.JSONParseException: 
{ isPublic: true, $or: [ { partnerID: /^CS/ }, { partnerID: /^CL/ } ] }
                                      ^
2019-11-12 14:40:48.194  INFO 10368 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-11-12 14:40:48.205  INFO 10368 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-11-12 14:40:48.215 ERROR 10368 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'partnerController': Unsatisfied dependency expressed through field 'parterService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'partnerServiceImp': Unsatisfied dependency expressed through field 'partnerRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'partnerRepository': Invocation of init method failed; nested exception is com.mongodb.util.JSONParseException: 
{ isPublic: true, $or: [ { partnerID: /^CS/ }, { partnerID: /^CL/ } ] }
                                      ^
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:598) ~[spring-beans-5.1.10.RELEASE.jar:5.1.10.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.10.RELEASE.jar:5.1.10.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:376) ~[spring-beans-5.1.10.RELEASE.jar:5.1.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411) ~[spring-beans-5.1.10.RELEASE.jar:5.1.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.10.RELEASE.jar:5.1.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.10.RELEASE.jar:5.1.10.RELEASE]

任何人都可以帮助我解决此问题???? 谢谢!

0 个答案:

没有答案