Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

Query for Null or Missing Fields

On this page

  • Equality Filter
  • Type Check
  • Existence Check

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.


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.
←  Project Fields to Return from QueryIterate a Cursor in mongosh →