org.bson.json.JsonParseException: JSON reader 期待一个值但发现 ':' - Mongo springboot 中的查询抛出此错误

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

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

    @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.call(Unknown Source)
        at com.dashboard.services.impl.ProjectServiceImpl.fetchAllProjectBySearchString(ProjectServiceImpl.groovy:262)
        at com.dashboard.services.ProjectService$fetchAllProjectBySearchString[=15=].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' }} 
                        ]
                }
               ''')