gpt4 book ai didi

mongodb - org.bson.json.JsonParseException : JSON reader was expecting a value but found ':' - Mongo query in springboot throwing this error

转载 作者:行者123 更新时间:2023-12-04 07:54:25 26 4
gpt4 key购买 nike

我正在尝试获取在给定字段中具有匹配字符串的所有记录。

    @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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com