作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试获取在给定字段中具有匹配字符串的所有记录。
@Query('''{$match:
{ $or :
[
'name' : { $regex: ?0, $options:'i' },
'displayName' : { $regex: ?0, $options:'i' },
'url' : { $regex: ?0, $options:'i' }
]
}
}''')
Page<Project> findAllByNameOrSeoNameOrDomainNameOrUrl(String searchString, Pageable pageable)
我给出了这个查询,但它抛出了错误。
DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException - Using @ExceptionHandler com.dashboard.exception.handler.CustomExceptionHandler#handleAbstractException(Exception)
org.bson.json.JsonParseException: JSON reader was expecting a value but found ':'.
at org.springframework.data.mongodb.util.json.ParameterBindingJsonReader.readBsonType(ParameterBindingJsonReader.java:327)
at org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec.readList(ParameterBindingDocumentCodec.java:318)
at org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec.readValue(ParameterBindingDocumentCodec.java:297)
at org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec.decode(ParameterBindingDocumentCodec.java:195)
at org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec.decode(ParameterBindingDocumentCodec.java:61)
at org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec.readValue(ParameterBindingDocumentCodec.java:311)
at org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec.decode(ParameterBindingDocumentCodec.java:195)
at org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec.decode(ParameterBindingDocumentCodec.java:175)
at org.springframework.data.mongodb.repository.query.StringBasedMongoQuery.createQuery(StringBasedMongoQuery.java:121)
at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.doExecute(AbstractMongoQuery.java:116)
at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:101)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:618)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy117.findAllByNameOrSeoNameOrDomainNameOrUrl(Unknown Source)
at com.dashboard.repository.ProjectRepository$findAllByNameOrSeoNameOrDomainNameOrUrl$1.call(Unknown Source)
at com.dashboard.services.impl.ProjectServiceImpl.fetchAllProjectBySearchString(ProjectServiceImpl.groovy:262)
at com.dashboard.services.ProjectService$fetchAllProjectBySearchString$0.call(Unknown Source)
at com.dashboard.controller.api.ProjectController.fetchAll(ProjectController.groovy:89)
at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
最佳答案
我弄错了。我在做什么。 $or 中缺少大括号 {}。也不需要像@prasad_ 在评论中所说的那样 $match 。
@Query('''{ $or :
[
{'name' : { $regex: ?0, $options:'i' }},
{'displayName' : { $regex: ?0, $options:'i' }},
{'url' : { $regex: ?0, $options:'i' }}
]
}
''')
关于mongodb - org.bson.json.JsonParseException : JSON reader was expecting a value but found ':' - Mongo query in springboot throwing this error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66775260/
我是一名优秀的程序员,十分优秀!