Skip to main content

evaluate_where

Function evaluate_where 

Source
pub fn evaluate_where(doc: &Value, query: &Value) -> Result<bool, DbError>
Expand description

Evaluate a MongoDB-style WHERE clause against a single document.

Returns true if the document matches all conditions, false otherwise.

The query object is a JSON object where each key is either:

  • A field name (possibly dot-notation): { “role”: “admin” }
  • A logical operator: { “$or”: […], “$and”: […] }

Field conditions can be:

  • An implicit equality: { “role”: “admin” } (shorthand for $eq)
  • An operator object: { “age”: { “$gt”: 18 } }

Supported operators: Equality: $eq / $equals, $ne / $notEquals Numeric: $gt / $greaterThan, $gte, $lt / $lessThan, $lte String: $contains / $ct Logical: $or (array of sub-queries, any must match) $and (array of sub-queries, all must match)