mongo客户端查询语句:

db.log_table_name.find({"bPointInfo.resInfo.result.bData.sid":"e095385bff0f44de8638b31e9215cbd0","bPointInfo.userInfo":{$ne:null}
    
}).projection({})
   .sort({_id:-1})
   .limit(100)

或者

db.log_table_name.find({"bPointInfo.resInfo.result.bData.sid":"e095385bff0f44de8638b31e9215cbd0","bPointInfo.userInfo":{"$ne":null}
    
}).projection({})
   .sort({_id:-1})
   .limit(100)

java代码中这样赋值,以下代码有公司重写的mongo的字段

listSearch.add(new SearchField("buriedPointInfo.userInfo.sid",sid));
Map<String,Object> userInfoNonNullSearch = new HashMap<>();
userInfoNonNullSearch.put("$ne",null);
listSearch.add(new SearchField("buriedPointInfo.userInfo",userInfoNonNullSearch));

1. $ne

$ne:表示not equals 就是不等于的意思

# 查询某字段不为空的数据
db.hfijf.find({fieldName: {$ne:null}})
# 查询字段等于空的数据
db.hfijf.find({fieldName: {$eq:null}})

2. $exists

$exists:表示是否存在。值为false表示不存在,值为true表示存在

# 查询某字段不为空的数据
db.fdafdsa.find({fieldName:{$exists:true}})
# /查询某字段不存在的数据
db.fdafdsa.find({fieldName:{$exists:false}})
 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐