Mongodb 查询以检查参数是否为真而不为空

Mongodb query to check whether a parameter is true and not null

我正在使用 Spring Boot 创建应用程序。我为数据访问对象创建了一个 class,它将从 MongoDB 检索数据。

查询:查询的objective是检查参数(布尔变量-控件)是否not nulltrue

我试过以下查询:

    Query query = new Query();
    query.addCriteria(new Criteria().andOperator(
    Criteria.where({"control":{$ne:null}}),
Criteria.where("control").is(true)));

但是,这是不正确的。我们应该使用什么来检查变量是否不为空 - $exists 或 $ne?

您必须使用 if 条件检查 null,

if(null != control) {
            query.addCriteria(Criteria.where("status").is(control));
}

样本here