Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在spring boot中将查询字符串添加到mongo DB查询中?_Spring_Mongodb_Spring Boot_Mongodb Query_Microservices - Fatal编程技术网

如何在spring boot中将查询字符串添加到mongo DB查询中?

如何在spring boot中将查询字符串添加到mongo DB查询中?,spring,mongodb,spring-boot,mongodb-query,microservices,Spring,Mongodb,Spring Boot,Mongodb Query,Microservices,我有如下要求 从UI获取where子句作为字符串,在spring boot的where子句中添加字符串以查询mongo DB 例如:(eventType以'asdf'和age>fasdf开头)和(age使用spring数据使用@Query并在value参数中传递find查询 像 @查询({$and:[{'customUser.id':?0},{'deleted':false}],$or:[{'current_location':true},{'resident_of':true}]) 列出fin

我有如下要求

从UI获取where子句作为字符串,在spring boot的where子句中添加字符串以查询mongo DB


例如:(eventType以'asdf'和age>fasdf开头)和(age使用spring数据使用@Query并在value参数中传递find查询 像

@查询({$and:[{'customUser.id':?0},{'deleted':false}],$or:[{'current_location':true},{'resident_of':true}])

列出findAllByCustomUserA(字符串userId)

您的问题的解决方案

@查询(value=“{$and:[{'eventType':{$regex:'asdf/',$options:'i'}},{'age':{$lte:123},{$or[{'book':{$regex:'/234444',$options:'i'}]}”)

有关更多详细信息,请访问如何进行mongo查询


Sumit,谢谢您的回复,但这里的字符串是动态的,我们不知道该字符串中包含哪些列。@查询({$and:[{'customUser.id':?0},{'deleted':false}],$or:[{'current_location':true},{'resident_of':true}])列出findAllByCustomUserA(字符串用户id);?0在本例中使用动态字符串?0使用userId的字符串,在您的问题中使用相同的方法0,1,2是参数的索引这将起作用,如果列是固定的,如果列的数量不是固定的,我认为我们不能使用这种方法如果列是可变的,使用聚合机制将非常好,如果您可以提供示例或参考