skip to content
Alvin Lucillo

MongoDB Compass expression qry

/ 1 min read

💻 Tech

I learned that you can create complex conditions to query documents in MongoDB Compass. One of those is the use of expressions to create logical AND condition.

The example query below is equivalent to SQL’s e.employee_type='private' AND e.taxdue=e.taxwithheld. Just prepend the column name with the dollar sign to indicate that it’s a field name.

{
  "$and": [
    {"employee_type": "private"},
    {
      "$expr": {
        "$eq": ["$taxdue", "$taxwithheld"]
      }
    }
  ]
}