Query for Null or Missing Fields
On this page
This version of the documentation is archived and no longer supported. View the current documentation to learn how to upgrade your version of MongoDB server.
➤ Use the Select your language drop-down menu in the upper-right to set the language of the following examples.
Different query operators in MongoDB treat null
values differently.
Equality Filter
The query returns both documents in the collection.
Type Check
The query returns only the document where the item
field has a
value of null
.
Existence Check
The following example queries for documents that do not contain a field. [1]
The query only returns the document that does not contain the
item
field.
[1] | Starting in MongoDB 4.2, users can no longer use the query filter
$type: 0 as a synonym for
$exists:false . To query for null or missing fields, see
Query for Null or Missing Fields. |