泛型函式參考資料

一般函式

名稱 說明
CURRENT_DOCUMENT 傳回管道中目前正在處理的文件。
CONCAT 串連兩個以上相同類型的值。
LENGTH 計算 StringBytesArrayVectorMap 的長度。
REVERSE 反轉 StringBytesArray

CURRENT_DOCUMENT

語法:

current_document() -> MAP

說明:

評估結果為對應項,其中包含目前範圍內定義的所有欄位。合併或彙整多份文件時,或是想動態檢查文件中的欄位名稱時,這項功能就十分實用。

舉例來說,如要取得依欄位分組的文件清單:

Node.js

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

CONCAT

語法:

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

說明:

串連兩個以上相同類型的值。

範例:

concat(values)
「abc」、「def」 "abcdef"
[1, 2]、[3, 4] [1, 2, 3, 4]
b"abc", b"def" b"abcdef"
"abc", [1,2,3], "ghi" 錯誤
[1,2,3] 錯誤
"abc", null null
Node.js
concat(constant("Author ID: "), field("authorId"));

網頁

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

語法:

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

說明:

計算 StringBytesArrayVectorMap 值的長度。

範例:

length(value)
「你好」 5
[1, 2, 3, 4] 4
b"abcde" 5
null null
1 錯誤

REVERSE

語法:

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

說明:

反轉 StringBytesArray 值。

範例:

reverse(value)
「你好」 「olleh」
[1, 2, 3] [3, 2, 1]
b"abc" b"cba"
23 錯誤
null null

後續步驟