KeplerGrid guide

Find null and missing fields in MongoDB

A MongoDB filter that equals null can match both explicit nulls and missing fields. Use a type check or an existence check to see which situation you have.

Check what equality to null returns

Load the synthetic inventory, then open keplergrid_inventory.inventory in KeplerGrid in Read only mode. In Documents, paste this filter and click Run.

{ "reorderNote": null }

The results contain SKU-100, which has "reorderNote": null, and SKU-200, which has no reorderNote field. Choose JSON view in the results toolbar to see the difference in the documents.

Run one filter for each case

Explicit null

{ "reorderNote": { "$type": "null" } }

In this scalar-field example, the BSON null type check returns SKU-100.

Missing field

{ "reorderNote": { "$exists": false } }

This returns SKU-200 because the field is absent. A field set to null still exists.

Populated value

{ "reorderNote": { "$ne": null } }

This returns SKU-300, which has the note "Review next week". The filter also matches other present, non-null scalar values such as an empty string.

These examples assume reorderNote is scalar when present. If it can contain arrays, test against representative data because the query type check can also match an array element.

Use projection to return just the fields you need to inspect.

When excluding values, check how $nin handles a missing field.