Mongo:查找没有特定字段的项目 [英] Mongo: find items that don't have a certain field

查看:51
本文介绍了Mongo:查找没有特定字段的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在MongoDB中缺少某个字段的集合中搜索文档?

How to search for documents in a collection that are missing a certain field in MongoDB?

推荐答案

是的,可以使用 $ exists :

db.things.find( { a : { $exists : false } } ); // return if a is missing

为true时,$ exists匹配包含该字段的文档,包括该字段值为null的文档.如果为false,则查询仅返回不包含该字段的文档.

When is true, $exists matches the documents that contain the field, including documents where the field value is null. If is false, the query returns only the documents that do not contain the field.

这篇关于Mongo:查找没有特定字段的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆