Generic Functions
| Name | Description |
CURRENT_DOCUMENT
|
Returns the document currently being processed in the pipeline. |
CONCAT
|
Concatenates two or more values of same type. |
LENGTH
|
Calculates the length of a String, Bytes, Array, Vector, or Map.
|
REVERSE
|
Reverses a String, Bytes, or Array.
|
CURRENT_DOCUMENT
Syntax:
current_document() -> MAP
Description:
Evaluates to a map that holds all fields defined in the current scope. This is useful when merging or aggregating multiple documents together or when wanting to dynamically inspect the field names in the document.
For example, to get a list of documents grouped by a field:
Node.js
const cities = await db.pipeline()
.collection("/restaurants")
.aggregate({
groups: [ field("location.state").as("state") ],
accumulators: [ arrayAgg(currentDocument().as("restaurants")) ]
})
.execute();
CONCAT
Syntax:
concat[T <: STRING | BYTES | ARRAY](values:T ...) -> T
Description:
Concatenates two or more values of same type.
Examples:
| values | concat(values) |
|---|---|
| "abc", "def" | "abcdef" |
| [1, 2], [3, 4] | [1, 2, 3, 4] |
| b"abc", b"def" | b"abcdef" |
| "abc", [1,2,3], "ghi" | error |
| [1,2,3] | error |
| "abc", null | null |
Node.js
concat(constant("Author ID: "), field("authorId"));
Web
concat(constant("Author ID: "), field("authorId"));
Swift
let displayString = Constant("Author ID: ").concat([Field("authorId")])
Kotlin
val displayString = constant("Author ID: ").concat(field("authorId"))
Java
Expression displayString = constant("Author ID: ").concat(field("authorId"));
Python
Constant.of("Author ID: ").concat(Field.of("authorId"))
LENGTH
Syntax:
length[T <: STRING | BYTES | ARRAY | VECTOR | MAP](value: T) -> INT64
Description:
Calculates the length of a String, Bytes, Array, Vector, or Map value.
Examples:
| value | length(value) |
|---|---|
| "hello" | 5 |
| [1, 2, 3, 4] | 4 |
| b"abcde" | 5 |
| null | null |
| 1 | error |
REVERSE
Syntax:
reverse[T <: STRING | BYTES | ARRAY](value: T) -> T
Description:
Reverses a String, Bytes, or Array value.
Examples:
| value | reverse(value) |
|---|---|
| "hello" | "olleh" |
| [1, 2, 3] | [3, 2, 1] |
| b"abc" | b"cba" |
| 23 | error |
| null | null |