Mongodb mondodb match语句中值为空时排除字段
我正在编写一个spring boot mongo查询,以获取基于结果的名称csi,city。有时名称,CSI是空的,在这种情况下,我的查询不应该考虑空的字段。查询应该排除字段,如果数据在那里,它应该获取结果 比如说Mongodb mondodb match语句中值为空时排除字段,mongodb,spring-boot,mongodb-query,aggregation-framework,spring-data-mongodb,Mongodb,Spring Boot,Mongodb Query,Aggregation Framework,Spring Data Mongodb,我正在编写一个spring boot mongo查询,以获取基于结果的名称csi,city。有时名称,CSI是空的,在这种情况下,我的查询不应该考虑空的字段。查询应该排除字段,如果数据在那里,它应该获取结果 比如说 $match:{ name:'test', csi:'' //exclude if blank or null, city:'hyd' } 我的springboot查询是空的,但它不会忽略字段 @Aggregation({ "{\&qu
$match:{
name:'test',
csi:'' //exclude if blank or null,
city:'hyd'
}
我的springboot查询是空的,但它不会忽略字段
@Aggregation({
"{\"$match\": { \"$and\" : [ {\"name\" : { \"$ne\":\"\" }}, {\"name\" : ?0 }, {\"csi\" : { \"$ne\":\"\" }}, {\"csi\" : ?1 }, {\"city\" : { \"$ne\":\"\" }}, {\"city\" : ?2 }] }}"
})
List<data> getdata(String name, String csi, String city);
聚合({
“{\“$match\”:{\“$and\”:[{\“$name\”:{\“$ne\”:\”},{\“$name\”:?0},{\“csi\”:{\“$ne\”:\”},{\“csi\”:?1},{\“city\”:{\“$ne\”:\“\”},{\“city\”:{2}”
})
列出getdata(字符串名称、字符串csi、字符串城市);
你是说喜欢?是的,乔。类似的问题,但我在java中构造了mongo聚合查询