SQL 查询字段不为NULL且不为空:
SELECT * FROM 表名 WHERE 字段名 IS NOT NULL AND 字段名 != "";
若字段为空格,这个sql也可排除。
Mongo 查询字段不存在且不为空:
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; Query query = new Query(); Criteria c = new Criteria(); //c.orOperator(Criteria.where("字段名").exists(false), Criteria.where("字段名").is("")); c.andOperator(Criteria.where("字段名").exists(false), Criteria.where("字段名").is("")); query.addCriteria(c);
查询字段不存在或不为空:
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; Query query = new Query(); Criteria c = new Criteria(); c.orOperator(Criteria.where("字段名").exists(false), Criteria.where("字段名").is("")); //c.andOperator(Criteria.where("字段名").is(null), Criteria.where("字段名").is("")); query.addCriteria(c);