zoukankan      html  css  js  c++  java
  • mongodb中find $ne null 与$exists的区别

     $ne null 会把空列表也算入,即使不存在。

      $exists 的识别效果就比较好

    1.插入样例数据

    db.nullexistsdemo.insertMany( [{  "name" : "wqbin", "desc" : [ ] }
                             ,{  "name" : "wang", "desc" : {  } }
                             ,{  "name" : "quincy", "desc" : { "job" : "coder", "degree" : 4 } }
                             ,{  "name" : "wangyang"}]
                             )

    2.查看不等于null的数值

    db.nullexistsdemo.find({"desc.job":{"$ne":null}})

    db.nullexistsdemo.find({"desc.degree":{"$ne":null}})

    3.查看等于null的数值

    db.nullexistsdemo.find({"desc.degree":{"$eq":null}})
    db.nullexistsdemo.find({"desc.job":{"$eq":null}})

    4.查看不exists的数据

    db.nullexistsdemo.find({"desc.degree":{"$exists":null}})
    db.nullexistsdemo.find({"desc.job":{"$exists":false}})

    5.查看exists的数据

    db.nullexistsdemo.find({"desc.degree":{"$exists":1}})
    db.nullexistsdemo.find({"desc.job":{"$exists":""}})
    db.nullexistsdemo.find({"desc.job":{"$exists":true}})

  • 相关阅读:
    Springboot打jar 包
    mysql 函数
    SFTP的使用
    Java Swing
    消息中间件之ActiveMQ
    对象的四种引用关系
    vs的url传参
    后台管理两级类别
    $.dialog弹层---lhgDialog
    正则小数验证和去除中间空格
  • 原文地址:https://www.cnblogs.com/wqbin/p/11862844.html
Copyright © 2011-2022 走看看