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 (变量可以保存任何BSON类型的数据。要访问变量的值,请在变量名前加上双美元符号($$); i.e. "$$<variable>".$$);即"$$<variable>"。
If the variable references an object, to access a specific field in the object, use the dot notation; i.e. 如果变量引用对象,要访问对象中的特定字段,请使用点符号;即"$$<variable>.<field>"."$$<variable>.<field>"。
User Variables用户变量
User variable names can contain the ascii characters 用户变量名可以包含ascii字符[_a-zA-Z0-9] and any non-ascii character.[_a-zA-Z0-9]和任何非ascii字符。
User variable names must begin with a lowercase ascii letter 用户变量名必须以小写ascii字母[a-z] or a non-ascii character.[a-z]或非ascii字符开头。
System Variables系统变量
MongoDB offers the following system variables:MongoDB提供以下系统变量:
NOW | NOW returns the same value for all members of the deployment and remains the same throughout all stages of the aggregation pipeline.NOW为部署的所有成员返回相同的值,并在聚合管道的所有阶段保持不变。 |
CLUSTER_TIME |
|
ROOT | |
CURRENT |
|
REMOVE |
|
DESCEND | $redact expression.$redact表达式允许的结果之一。 |
PRUNE | $redact expression.$redact表达式允许的结果之一。 |
KEEP | $redact expression.$redact表达式允许的结果之一。 |
SEARCH_META |
|
USER_ROLES |
|