Global

Type Definitions

QueryOperators

Description:
  • Collection of query operators for MongoDB queries.
Source:
Properties:
Name Type Description
Equal string Equals operator: $eq - Matches values that are equal to a specified value.
Example:
const query = { age: QueryOperators.Equal, value: 25 };
  // This query matches users with age equal to 25
NotEqual string Not Equals operator: $ne - Matches values that are not equal to a specified value.
Example:
const query = { age: QueryOperators.NotEqual, value: 30 };
  // This query matches users with age not equal to 30
GreaterThan string Greater Than operator: $gt - Matches values that are greater than a specified value.
Example:
const query = { age: QueryOperators.GreaterThan, value: 25 };
  // This query matches users older than 25
GreaterThanOrEqual string Greater Than or Equal To operator: $gte - Matches values that are greater than or equal to a specified value.
Example:
const query = { age: QueryOperators.GreaterThanOrEqual, value: 25 };
  // This query matches users aged 25 or older
LessThan string Less Than operator: $lt - Matches values that are less than a specified value.
Example:
const query = { age: QueryOperators.LessThan, value: 30 };
  // This query matches users younger than 30
LessThanOrEqual string Less Than or Equal To operator: $lte - Matches values that are less than or equal to a specified value.
Example:
const query = { age: QueryOperators.LessThanOrEqual, value: 30 };
  // This query matches users aged 30 or younger
In string In operator: $in - Matches any of the values specified in an array.
Example:
const query = { status: QueryOperators.In, value: ["active", "inactive"] };
  // This query matches users with "active" or "inactive" status
NotIn string Not In operator: $nin - Matches values that are not in the specified array.
Example:
const query = { status: QueryOperators.NotIn, value: ["inactive"] };
  // This query matches users not in "inactive" status
Exists string Exists operator: $exists - Matches documents that have the specified field.
Example:
const query = { age: QueryOperators.Exists, value: true };
  // This query matches users with an "age" field
Type string Type operator: $type - Matches documents where the value of a field has a specific BSON data type.
Example:
const query = { age: QueryOperators.Type, value: "number" };
  // This query matches users with "age" as a number
Modulus string Modulus operator: $mod - Performs a modulo operation on the value of a field.
Example:
const query = { age: QueryOperators.Modulus, value: [2, 1] };
  // This query matches users with even ages
Regex string Regular Expression operator: $regex - Matches documents where a field matches a regular expression pattern.
Example:
const query = { name: QueryOperators.Regex, value: /^A/ };
  // This query matches users with names starting with "A"
Text string Text Search operator: $text - Performs a full-text search on a field.
Example:
const query = { [QueryOperators.Text]: { $search: "Alice" } };
  // This query searches for users with "Alice" in their names (requires text index)
TextOperators Object Text operator: $text - Performs a full-text search on a field.
Properties
Name Type Description
Search string Search property for $text operator.
Language string Language property for $text operator.
CaseSensitive string CaseSensitive property for $text operator.
DiacriticSensitive string DiacriticSensitive property for $text operator.
Where string Where operator: $where - Matches documents that satisfy a JavaScript expression.
Example:
const query = { [QueryOperators.Where]: "this.age > 25" };
  // This query matches users with age greater than 25 using a JavaScript expression
Size string Size operator: $size - Matches documents where an array field has a specific size.
Example:
const query = { name: QueryOperators.Size, value: 5 };
  // This query matches users with a name of exactly 5 characters
All string All Elements Match operator: $all - Matches documents where all elements in an array field match a specified condition.
Example:
const query = { hobbies: QueryOperators.All, value: ["reading", "swimming"] };
  // This query matches users with all specified hobbies
ElemMatch string Element Match operator: $elemMatch - Matches documents where at least one element in an array field matches a specified condition.
Example:
const query = { hobbies: QueryOperators.ElemMatch, value: { [QueryOperators.Equal]: "swimming" } };
  // This query matches users with "swimming" as one of their hobbies
Not string Not operator: $not - Inverts the effect of a query expression.
Example:
const query = { age: QueryOperators.Not, value: { [QueryOperators.GreaterThan]: 25 } };
  // This query matches users with age not greater than 25
Nor string Nor operator: $nor - Joins query clauses with a logical NOR and selects the documents that fail all the query clauses.
Example:
const query = {
  [QueryOperators.Nor]: [
    { age: QueryOperators.LessThan, value: 25 },
    { age: QueryOperators.GreaterThan, value: 30 }
  ]
  };
  // This query matches users who are neither younger than 25 nor older than 30
Or string Or operator: $or - Joins query clauses with a logical OR and selects the documents that satisfy at least one of the query clauses.
Example:
const query = {
  [QueryOperators.Or]: [
    { age: QueryOperators.Equal, value: 25 },
    { age: QueryOperators.Equal, value: 30 }
  ]
  };
  // This query matches users who are either aged 25 or aged 30
And string And operator: $and - Joins query clauses with a logical AND and selects the documents that satisfy all the query clauses.
Example:
const query = {
  [QueryOperators.And]: [
    { age: QueryOperators.GreaterThanOrEqual, value: 22 },
    { status: QueryOperators.Equal, value: "active" }
  ]
  };
  // This query matches users who are aged 22 and have "active" status
GeoWithin string GeoWithin operator: $geoWithin - Matches documents that are within a specified geometry.
Example:
const query = {
  location: {
    [QueryOperators.GeoWithin]: {
      [QueryOperators.Geometry]: {
        type: "Polygon",
        coordinates: [ // Polygon coordinates ]
      }
    }
  }
  };
GeoIntersects string GeoIntersects operator: $geoIntersects - Matches documents that intersect with a specified geometry.
Example:
const query = {
  location: {
    [QueryOperators.GeoIntersects]: {
      [QueryOperators.Geometry]: {
        type: "Point",
        coordinates: [ // Point coordinates ]
      }
    }
  }
  };
Near string Near operator: $near - Returns geospatial objects in proximity to a specified point.
Example:
const query = {
  location: {
    $near: {
      [QueryOperators.Geometry]: {
        type: "Point",
        coordinates: [ // Point coordinates ]
      },
      $maxDistance: 1000 // Maximum distance in meters
    }
  }
  };
NearSphere string Near Sphere operator: $nearSphere - Returns geospatial objects in proximity to a specified point on a sphere.
Example:
const query = {
  location: {
    [QueryOperators.NearSphere]: {
      [QueryOperators.Geometry]: {
        type: "Point",
        coordinates: [ // Point coordinates ]
      },
      $maxDistance: 1000 // Maximum distance in radians
    }
  }
  };
Geometry string Geometry operator: $geometry - Defines a geospatial shape for use with the $geoWithin and $geoIntersects operators.
Example:
const geometry = {
  type: "Polygon",
  coordinates: [ // Polygon coordinates ]
  };
CenterSphere string Center Sphere operator: $centerSphere - Defines a circle on a sphere for use with the $geoWithin and $geoIntersects operators.
Example:
const circle = {
  center: [ // Center coordinates ],
  radius: 1000 // Radius in radians
  };
Box string Box operator: $box - Defines a rectangle for use with the $geoWithin and $geoIntersects operators.
Example:
const query = {
  location: {
    [QueryOperators.GeoWithin]: {
      [QueryOperators.Box]: [
        [10, 20], // Bottom-left corner coordinates
        [30, 40]  // Top-right corner coordinates
      ]
    }
  }
  };
  // This query matches locations within the specified rectangle (requires geospatial data)
Polygon string Polygon operator: $polygon - Defines a polygon for use with the $geoWithin and $geoIntersects operators.
Example:
const query = {
  location: {
    [QueryOperators.GeoWithin]: {
      [QueryOperators.Polygon]: [
        [0, 0],   // Vertex 1 coordinates
        [0, 10],  // Vertex 2 coordinates
        [10, 10]  // Vertex 3 coordinates
      ]
    }
  }
  };
  // This query matches locations within the specified polygon (requires geospatial data)
UniqueDocs string Unique Documents operator: $uniqueDocs - Specifies that the results of a geospatial query should include only one of each distinct document.
Example:
const query = { age: QueryOperators.UniqueDocs, value: true };
  // This query returns unique documents based on geospatial query results
Comment string Comment operator: $comment - Adds a comment to a query to help with debugging or profiling.
Example:
const query = {
  age: QueryOperators.Equal,
  value: 25,
  [QueryOperators.Comment]: "Find users with age equal to 25"
  };
  // This query adds a comment for documentation or profiling purposes
Collection of query operators for MongoDB queries.
Type:
  • Object