Skip to content
All writing Part 08 of 09 · [object Object]
Engineering · 2 min read

MongoDB Operators & Vocabulary: SQL Intent to Documents

Translating SQL intent into MongoDB: comparison, $in, $regex, and $exists operators, a SQL→Mongo mapping table, and the relational→document vocabulary (table = collection, row = document).

Mongo speaks documents, so what you’re translating is the operation’s intent, not SQL syntax.

{ field: {$op: value} }

  • Equal $eq: the default, no operator needed. {field: <cond>}
  • Others: { age: {$gt: 30} }
  • { age: { $gt: 20, $lt: 40 } } // 20 < age < 40

Common operators

  • Comparison
    • $gt / $gte / $lt / $lte
    • $eq / $ne
    • $in / $nin: matches any / matches none in a list, like SQL’s IN
      • { type: { $in: ["a","b","c"] } }
  • String
    • $regex: like SQL’s LIKE
      • { name: { $regex: "abc", $options: "i" } } (i = case-insensitive)
  • Existence
    • $exists: whether this field is present at all
      • In Mongo, Absent ≠ null: username: null means “the field is there, explicitly with no value”; Absent means “the document doesn’t have this key at all”
  • Logical$or / $and / $nor take an array
    • { $or: [ { age: { $lt: 18 } }, { vip: true } ] }

SQL → MongoDB

SQLMongoDB
SELECT col{ $project: {...} } (or the find projection parameter)
GROUP BY{ $group: { _id: "$field", ... } }
ORDER BY{ $sort: {...} }
IN (...){ field: { $in: [a, b, c] } }
IS NULL{ field: null } or { field: { $exists: false } }
LIMIT{ $limit: n }

Vocabulary: relational → MongoDB

Relational (Postgres)MongoDBNotes
TableCollectiona group of documents
RowDocumenta JSON/BSON object
ColumnFieldbut no fixed schema — fields can differ document to document
Schema(not enforced)schema is flexible, varies by document
Primary key_idauto-added, unique

References

Related: back to the Cross-Engine DB Query overview; see how LIKE / ILIKE substring search maps to $regex, and how it all ties to the portable SQL core.

Tags #mongodb #databases
// connect

Be brave | Be wise | Be grateful

21 BreakinCode

// elsewhere
LinkedInMedium (lang: en)Life RecordYoutube
wh:~$William Hung· © 2026 Taipei · GMT+8 · Available for collaboration