MongoDB $not vs $or + $exists: false: Which is more efficient for queries including missing fields?

Hey buddy,
long story short;

  1. Which is more efficient? $or with { $gte } + { $exists: false }, because each branch can use its own index.
  2. Does $not behave differently with missing fields? Yes. $not matches >= 18, and missing, null, or non-numeric values — it’s broader than $or.
  3. Which scales better with compound indexes? $or scales better. You can tune each branch with its own (possibly partial) index. $not usually can’t take advantage of compound indexes efficiently.
3 Likes