Prepare records with missing and null statuses
Run this once in mongosh against an empty practice database on a disposable MongoDB instance. Then open keplergrid_case_lab.cases in KeplerGrid in Read only mode.
const lab = db.getSiblingDB("keplergrid_case_lab")
lab.cases.insertMany([
{ _id: "C-001", status: "open", events: ["received", "triaged", "assigned", "notified"] },
{ _id: "C-002", status: "closed" },
{ _id: "C-003" },
{ _id: "C-004", status: null },
{ _id: "C-005", status: "queued" },
{ _id: "C-006", status: "void" }
])
Filter out closed and void cases
In Documents, paste this into Filter and select Run.
{ "status": { "$nin": ["closed", "void"] } }
The matches are C-001, C-003, C-004, and C-005. Inspect C-003 in JSON view to see that it has no status field. C-004 has a field with an explicit null value.
Keep only cases with a status field
Replace the filter with this one. Put both operators inside the same field object so both conditions apply.
{ "status": { "$exists": true, "$nin": ["closed", "void"] } }
C-003 drops out. C-004 still matches because the field exists, and null is outside the excluded list.
Filter out explicit null as well
{ "status": { "$exists": true, "$nin": ["closed", "void", null] } }
Run again to get C-001 and C-005. For a fixed set of allowed statuses, use a positive $in list if you want unknown future values to stay out of the result.
Compare null and missing values or see how $in matches an allowed list.