Query Operators


Query operators provide ways to locate data within the MapQL instance.

Comparison

$eq -- Matches values that are equal to a specified value.

The $eq operator matches documents where the value of a field equals (==) the specified value. This is also the default find() operator.

<value> OR { <field>: { $eq: <value> } }

The following examples query against MapQL with the following documents:

MapQLInstance.set('foo1', 'bar');
MapQLInstance.set('foo2', { bar: 'baz' });
MapQLInstance.set('bar', 'foo3');

Select all documents where the value equals { bar: 'baz' } or bar. If a Document is added to the Cursor by it's key value, Symbol(bykey) will be true.

// Cursor [ Document { _id: 'foo2', value: { bar: 'baz' } } ]
MapQLInstance.find({ bar: { $eq:'baz' } });
// Cursor [ Document { _id: 'foo1', value: 'bar' } ]
MapQLInstance.find({ $eq:'bar' });
/* Cursor [ Document { _id: 'bar', value: 'foo3', [Symbol(bykey)]: true }, Document { _id: 'foo1', value: 'bar', [Symbol(bykey)]: false } ] */
MapQLInstance.find('bar');
$gt -- Matches values that are greater than a specified value.

The $gt operator selects those documents where the value is greater than (>) the specified value.

{ <field>: { $gt: <value> } }

The following examples query against MapQL with the following documents:

MapQLInstance.set('foo1', 10);
MapQLInstance.set('foo2', { val: 10 })
MapQLInstance.set('foo3', { val: 15 });

Select all documents where the field value is greater than number 12. If a Document is added to the Cursor by it's key value, Symbol(bykey) will be true.

// Cursor [ Document { _id: 'foo3', value: { val: 15 } } ]
MapQLInstance.find({ val: { $gt: 12 } });
// Cursor [ Document { _id: foo1, value: 10 } ]
MapQLInstance.find({ $gt: 5 });
$gte -- Matches values that are greater than or equal to a specified value.

The $gte operator selects the documents where the value of the field is greater than or equal to (>=) the specified value.

$lt -- Matches values that are less than a specified value.

The $lt operator selects the documents where the value of the field is less than (<) the specified value.

$lte -- Matches values that are less than or equal to a specified value.

The $lte operator selects the documents where the value of the field is less than or equal to (<=) the specified value.

$ne -- Matches all values that are not equal to a specified value.

The $ne operator selects the documents where the value of the field is not equal (!=) to the specified value. This includes documents that do not contain the field.

$in -- Matches any of the values specified in an array.

The $in operator selects the documents where the value of a field equals any value in the specified Array.

$nin -- Matches none of the values specified in an array.

The $nin operator selects the documents where the field value is not in the specified Array or the field does not exist.

Logical

$or -- Joins query clauses with a logical OR returns all documents that match the conditions of either clause.

The $or operator performs a logical OR operation on an Array of two or more expressions and selects the documents that satisfy at least one of the expressions.

$and -- Joins query clauses with a logical AND returns all documents that match the conditions of both clauses.

The $and operator performs a logical AND operation on an Array of two or more expressions (e.g. expression1, expression2, etc.) and selects the documents that satisfy all the expressions in the Array.

Element

$exists -- Matches documents that have the specified field.

When boolean is true, $exists matches the documents that contain the field, including documents where the field value is null. If boolean is false, the query returns only the documents that do not contain the field.

$type -- Selects documents if a field is of the specified type.

The $type operator selects the documents where the value of the field is an instance of the specified data type. Querying by data type is useful when dealing with highly unstructured data where data types are not predictable.

Evaluation

$regex -- Selects documents where values match a specified regular expression.

Provides regular expression capabilities for pattern matching strings in queries. MapQL() uses JavaScript regular expressions (RegExp).

$where -- Matches documents that satisfy a JavaScript expression.

Use the $where operator to pass a JavaScript function to the query system. The $where provides greater flexibility, but requires that the MapQL() processes the function for each document. Reference the document in the function using either this or as the first function argument.

Array

$size -- Selects documents if the array field is a specified size.

The $size operator matches any Array with the number of elements specified by the argument.

results matching ""

    No results matching ""