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 (".
For example:
Variable | Access via $ | Brief Description |
close |
| returns the absolute value of a number |
context |
| returns a numeric value between 0 and π radians for x between -1 and 1 |
cursor |
| returns the inverse hyperbolic cosine of a number |
date |
| N/A |
env |
| N/A |
now |
| A variable that returns the current datetime value |
random |
| returns a floating-point, pseudo-random number in the range 0 to less than 1 |
remove |
| A variable which evaluates to the missing value |
request |
| N/A |
root |
| References the root currently being processed in the aggregation pipeline stage |
script |
| N/A |
var |
| N/A |
Last updated