汎用関数のリファレンス

汎用関数

名前 説明
CURRENT_DOCUMENT パイプラインで現在処理中のドキュメントを返します。
CONCAT 同じ型の 2 つ以上の値を連結します。
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

説明:

同じ型の 2 つ以上の値を連結します。

例:

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" エラー
[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)
"hello" 5
[1, 2, 3, 4] 4
b"abcde" 5
null null
1 エラー

REVERSE

構文:

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

説明:

StringBytes 値または Array 値を元に戻します。

例:

reverse(value)
"hello" "olleh"
[1, 2, 3] [3, 2, 1]
b"abc" b"cba"
23 エラー
null null

次のステップ