Spring boot 在springboot应用程序中使用mongotemplate实现Like运算符
在使用mongotemplate的spring Boot应用程序中,我需要编写一个查询,以使用Spring boot 在springboot应用程序中使用mongotemplate实现Like运算符,spring-boot,mongotemplate,Spring Boot,Mongotemplate,在使用mongotemplate的spring Boot应用程序中,我需要编写一个查询,以使用LIKE操作符获得结果。但是在mongotemplate中,就像在SQL中一样,我没有可以使用的直接查询 我尝试了一些选项,如Aggregate和regex方法,但没有成功 在MongoDB也尝试了同样的方法 db.getCollection('Months').find({"name":/Jan/}). 因此,在月份表中,我必须检索“name”列中包含“Jan”字母的结果。但是在运行这个查询时,假设
LIKE
操作符获得结果。但是在mongotemplate中,就像在SQL中一样,我没有可以使用的直接查询
我尝试了一些选项,如Aggregate
和regex
方法,但没有成功
在MongoDB也尝试了同样的方法
db.getCollection('Months').find({"name":/Jan/}).
因此,在月份
表
中,我必须检索“name”列中包含“Jan”字母的结果。但是在运行这个查询时,假设我有一个名为'DecJan'的条目,在这种情况下,我无法检索它
Query constantQuery = new Query();``
constantQuery.addCriteria(Criteria.where("name").regex("DecJan", "i"));
List<Months> pp = this.mongoTemplate.find(constantQuery, Months.class);
queryconstantquery=newquery()``
constantQuery.addCriteria(Criteria.where(“name”).regex(“DecJan”,“i”));
List pp=this.mongoTemplate.find(constantQuery,Months.class);
所以,预期的结果是,如果我在一个表中有两个条目,比如“一月”,“十二月”
在查询中,如果我通过“Jan”,我需要使用mongotemplate检索两个结果。更新的复制链接不引用所需的mongotemplate实例 顺便说一下,我使用aggregationOperation进行了同样的操作,并得到了结果
AggregationOperation operation = Aggregation.match(Criteria.where("name").regex(pattern, "i"));
Aggregation aggregation = Aggregation.newAggregation(aggregate, operation);