Funkcje ogólne
| Nazwa | Opis |
CURRENT_DOCUMENT
|
Zwraca dokument aktualnie przetwarzany w potoku. |
CONCAT
|
Łączy co najmniej 2 wartości tego samego typu. |
LENGTH
|
Oblicza długość String, Bytes, Array, Vector lub Map.
|
REVERSE
|
Cofa działanie String, Bytes lub Array.
|
CURRENT_DOCUMENT
Składnia:
current_document() -> MAP
Opis:
Zwraca mapę zawierającą wszystkie pola zdefiniowane w bieżącym zakresie. Jest to przydatne podczas scalania lub agregowania wielu dokumentów albo gdy chcesz dynamicznie sprawdzać nazwy pól w dokumencie.
Aby na przykład uzyskać listę dokumentów pogrupowanych według pola:
Node.js
const cities = await db.pipeline()
.collection("/restaurants")
.aggregate({
groups: [ field("location.state").as("state") ],
accumulators: [ arrayAgg(currentDocument().as("restaurants")) ]
})
.execute();
CONCAT
Składnia:
concat[T <: STRING | BYTES | ARRAY](values:T ...) -> T
Opis:
Łączy co najmniej 2 wartości tego samego typu.
Przykłady:
| wartości | concat(values) |
|---|---|
| „abc”, „def” | „abcdef” |
| [1, 2], [3, 4] | [1, 2, 3, 4] |
| b"abc", b"def" | b"abcdef" |
| „abc”, [1,2,3], „ghi” | błąd |
| [1,2,3] | błąd |
| "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
Składnia:
length[T <: STRING | BYTES | ARRAY | VECTOR | MAP](value: T) -> INT64
Opis:
Oblicza długość wartości String, Bytes, Array, Vector lub Map.
Przykłady:
| wartość | length(value) |
|---|---|
| „Witaj” | 5 |
| [1, 2, 3, 4] | 4 |
| b"abcde" | 5 |
| null | null |
| 1 | błąd |
ODWRÓĆ
Składnia:
reverse[T <: STRING | BYTES | ARRAY](value: T) -> T
Opis:
Odwraca wartość String, Bytes lub Array.
Przykłady:
| wartość | reverse(value) |
|---|---|
| „Witaj” | „olleh” |
| [1, 2, 3] | [3, 2, 1] |
| b"abc" | b"cba" |
| 23 | błąd |
| null | null |