zoukankan      html  css  js  c++  java
  • 13.Query for Null or Missing Fields-官方文档摘录

    1 插入数据

    db.inventory.insertMany([
       { _id: 1, item: null },
       { _id: 2 }
    ])

    2 查询null值

    db.inventory.find({itme:null})

    如果要精确查找到对应的null的字段,应该

    db.inventory.find({item:{$type:10}})

    3 查询是否存在这个元素

    db.inventory.find({item:{$exists:false}})

    Different query operators in MongoDB treat null values differently.

    This page provides examples of operations that query for null values using the db.collection.find()method in the mongo shell. The examples on this page use the inventory collection. To populate theinventory collection, run the following:

     
    db.inventory.insertMany([
       { _id: 1, item: null },
       { _id: 2 }
    ])
    

    You can run the operation in the web shell below:

    Equality Filter

    The item null } query matches documents that either contain the item field whose value is null orthat do not contain the item field.

    For example, the following query returns both documents:

    db.inventory.find( { item: null } )
    

    Type Check

    The item $type: 10 } query matches documents that contains the item field whose value isnull only; i.e. the value of the item field is of BSON Type Null (i.e. 10) :

    db.inventory.find( { item : { $type: 10 } } )
    

    The query returns only the document where the item field has a null value.

    Existence Check

    The item $exists: false } query matches documents that do not contain the item field:

    db.inventory.find( { item : { $exists: false } } )
    

    The query returns only the document that does not contain the item field:

    SEE ALSO

    The reference documentation for the $type and $exists operators.

  • 相关阅读:
    Vue条件判断
    揭秘webpack plugin
    vue实现网络图片瀑布流 + 下拉刷新 + 上拉加载更多
    npx 是什么?
    PAT 1100 Mars Numbers[难]
    PAT 1075 PAT Judge[比较]
    PAT 1083 List Grades[简单]
    PAT 1082 Read Number in Chinese[难]
    PAT 1135 Is It A Red-Black Tree[难]
    PAT 1127 ZigZagging on a Tree[难]
  • 原文地址:https://www.cnblogs.com/olinux/p/7261787.html
Copyright © 2011-2022 走看看