Riferimento per le funzioni generiche

Funzioni generiche

Nome Descrizione
CURRENT_DOCUMENT Restituisce il documento attualmente in elaborazione nella pipeline.
CONCAT Concatena due o più valori dello stesso tipo.
LENGTH Calcola la lunghezza di un String, Bytes, Array, Vector o Map.
REVERSE Inverte un String, Bytes o Array.

CURRENT_DOCUMENT

Sintassi:

current_document() -> MAP

Descrizione:

Restituisce una mappa che contiene tutti i campi definiti nell'ambito corrente. Questa funzionalità è utile quando si uniscono o si aggregano più documenti o quando si vogliono ispezionare dinamicamente i nomi dei campi nel documento.

Ad esempio, per ottenere un elenco di documenti raggruppati per campo:

Node.js

const cities = await db.pipeline()
  .collection("/restaurants")
  .aggregate({
    groups: [ field("location.state").as("state") ],
    accumulators: [ arrayAgg(currentDocument().as("restaurants")) ]
   })
  .execute();

CONCAT

Sintassi:

concat[T <: STRING | BYTES | ARRAY](values:T ...) -> T

Descrizione:

Concatena due o più valori dello stesso tipo.

Esempi:

valori concat(values)
"abc", "def" "abcdef"
[1, 2], [3, 4] [1, 2, 3, 4]
b"abc", b"def" b"abcdef"
"abc", [1,2,3], "ghi" errore
[1,2,3] errore
"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
Android
val displayString = constant("Author ID: ").concat(field("authorId"))
Java
Android
Expression displayString = constant("Author ID: ").concat(field("authorId"));
Python
Constant.of("Author ID: ").concat(Field.of("authorId"))

LENGTH

Sintassi:

length[T <: STRING | BYTES | ARRAY | VECTOR | MAP](value: T) -> INT64

Descrizione:

Calcola la lunghezza di un valore String, Bytes, Array, Vector o Map.

Esempi:

valore length(value)
"ciao" 5
[1, 2, 3, 4] 4
b"abcde" 5
null null
1 errore

REVERSE

Sintassi:

reverse[T <: STRING | BYTES | ARRAY](value: T) -> T

Descrizione:

Inverte un valore String, Bytes o Array.

Esempi:

valore reverse(value)
"ciao" "olleh"
[1, 2, 3] [3, 2, 1]
b"abc" b"cba"
23 errore
null null

Passaggi successivi