$exists
noun
say it: “DOL-er ig-ZISTS” /ˈdɑlər ɪɡˈzɪsts/
A MongoDB filter operator that matches documents by whether they have a certain field at all.
What does $exists do in a MongoDB filter?
$exists matches documents by whether a field is there at all: { $exists: true } finds documents that have it, whatever its value (even null), and false finds the ones without it.
db.recipes.find({ notes: { $exists: false } }, { _id: 0, name: 1 });
// [ { name: 'Tea' } ] (Toast has notes: null, so it isn't listed)
In a sentence
- “Unlike a filter for null, $exists true finds a field even when it holds null.”
- “$exists set to false found the old recipes saved before the photo field was added.”
Level: Apprentice · More MongoDB terms at this level
Updated