Mongodb spring mongo db中的条件匹配操作
我使用下面的匹配操作来匹配Spring数据Mongodb中的某些条件Mongodb spring mongo db中的条件匹配操作,mongodb,spring-boot,spring-data-jpa,aggregation-framework,spring-data-mongodb,Mongodb,Spring Boot,Spring Data Jpa,Aggregation Framework,Spring Data Mongodb,我使用下面的匹配操作来匹配Spring数据Mongodb中的某些条件 MatchOperation propertyMatchOperation = Aggregation.match( Criteria. where("abc1").is(abcVal1) .and("abc2").is(abcVal2) .and("abc3").is(abcVal3)
MatchOperation propertyMatchOperation = Aggregation.match(
Criteria.
where("abc1").is(abcVal1)
.and("abc2").is(abcVal2)
.and("abc3").is(abcVal3)
.and("abc4").is(abcVal4)
.and("abc5").is(abcVal5)
);
当某个值为null
或“
”时,它会检查mongodb中的”
值,而该参数不应包含在查询中
假设,abcVal3
为null
,则上述匹配操作将只搜索参数中的null
值,并发送零结果,即使其他条件正在匹配
有没有办法让它成为有条件的独占或包含?我认为匹配不会有问题。如果
abc3
为null
,其他4个变量满足您的条件(因为和
),它将返回匹配的数据,如“abc1:“first”,“abc2:“second”,“abc3:“third”,“abc4:”“abc5:”。所以,如果我必须把马赫数设为第一,第二,第三,不管abc4和abc5的值是多少,这是不会发生的。它用值“”查询abc4和abc4,这是否意味着您发送了abc1=“first”
,abc2=“second”
,abc3=“third”
,abc4=null
,abc5=null
?或者您正在为null
发送”
?是,因为默认vault值将为null或“”。