Search…
⌃K

Variables

Aggregation expressions can use both user-defined and system variables.
Variables can hold any BSON type data. To access the value of the variable, prefix the variable name with double dollar signs (
);i.e."); i.e. "
".
For example:
Variable
Access via $
Brief Description
close
$$CLOSE
returns the absolute value of a number
context
$$CONTEXT
returns a numeric value between 0 and π radians for x between -1 and 1
cursor
$$CURSOR
returns the inverse hyperbolic cosine of a number
date
$$DATE
N/A
env
$$ENV
N/A
now
$$NOW
A variable that returns the current datetime value
random
$$RANDOM
returns a floating-point, pseudo-random number in the range 0 to less than 1
remove
$$REMOVE
A variable which evaluates to the missing value
request
$$REQUEST
N/A
root
$$ROOT
References the root currently being processed in the aggregation pipeline stage
script
$$SCRIPT
N/A
var
$$VAR
N/A