$type

noun

say it: “DOL-er TYPE” /ˈdɑlər ˈtaɪp/

A MongoDB filter operator that matches documents by the kind of value a field holds, such as text, a number or a date.

What does $type do in a MongoDB filter?

$type matches documents by the kind of value a field holds, named such as "string", "number", "date" or "array". It finds data entered the wrong way, such as minutes saved as text.

db.recipes.find({ minutes: { $type: "string" } }, { _id: 0, name: 1, minutes: 1 });
// [ { name: 'Sunday Roast', minutes: '90' } ]

In a sentence

  • “After fixing the import, a query with $type confirmed that every price was a number.”
  • “$type "string" found the three recipes whose minutes had been typed in as text.”

Level: Journeyman · More MongoDB terms at this level

Updated