Docs Menu

Query for Null or Missing Fields


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.

The query returns both documents in the collection.

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

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.

Tip
See also:

Reference documentation for the $type and $exists operators.

[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.

Select your language

Give Feedback
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.