mongodb查询null

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

这三条数据的item字段,分别为null,不存在,为数字1。
db.inventory.find({item:null}),该{ item : null }查询匹配包含item其值为null 或不包含该item字段的字段的文档。
db.inventory.find( { item : { $type: 10 } } ),只查询出item为null的文档。
db.inventory.find( { item : { $exists: false } } ),只查询出item缺失的文档。
db.inventory.find( { item : { $exists: true } } ),只查询出item存在的文档,包括item为null的文档。

posted @ 2022-05-09 19:23  mentalidade  阅读(354)  评论(0编辑  收藏  举报