您当前的位置: 首页 >  mongodb

qq_34412985

暂无认证

  • 2浏览

    0关注

    1061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

mongodb下查询某个字段不为空的文档

qq_34412985 发布时间:2021-11-16 20:16:08 ,浏览量:2

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 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}})  

关注
打赏
1653291990
查看更多评论
立即登录/注册

微信扫码登录

0.0436s