Literal Operators

Operator

Description

Example

$literal

Allows the insertion of any literal value. This is used mainly when you'd like to use a value that would otherwise be evaluated as an expression.

pricesEqual: { $eq: [ "$cashValue", { $literal: "$10" } ] }

$string

Allows the insertion of a string literal. The value must be a string or an expression that evaluates to a string.

{ "$concat": ["c_pants", { "$string": "c_pants" }] } -> "clown c_pants"

$number

Allows the insertion of a number value as a literal where a property name would otherwise be expected. The value must be a number or an expression that evaluates to a number.

{ "$add": ["c_scalar", { "$number": 1.23 }] }

$integer

Allows the insertion of an integer value as a literal where a property name would otherwise be expected. The value must be an integer or an expression that evaluates to an integer.

{ "$add": ["c_ints", { "$integer": 10 }] }

$boolean

Allows the insertion of a boolean value as a literal where a property name would otherwise be expected. The value must be a boolean or an expression that evaluates to a boolean.

{ "alwaysFirstName": { "$first": { "$cond": [{ "$boolean": true }, "name.first", "name.last"] } } }

$date

Allows the insertion of a date value as a literal where a property name would otherwise be expected. The value must be a date or an expression that evaluates to a date.

{ "offsetDate": { "$add": [{ "$date": "2015-06-07T14:48:00.000Z" }, "c_offset"] } }

$objectId

Allows the insertion of an objectId value as a literal where a property name would otherwise be expected. The value must be an objectId or an expression that evaluates to an objectId.

{ "$cmp": [{ "$objectId": "561614700000000000000000" }, "_id"] }

$array

Allows the insertion of an array value as a literal where a property name would otherwise be expected. The value must be an array or an expression that evaluates to an array.

{ "$setUnion": [{ "$array": ["000000000000000000000007"] }, "roles"] }

$object

Allows the insertion of an object value as a literal where a property name would otherwise be expected. The value must be an object or an expression that evaluates to an object.

{ "$eq": [{ "$object": { "street": "Easy St" } }, "c_address"] }