일반 함수 참조

일반 함수

이름 설명
CURRENT_DOCUMENT 파이프라인에서 현재 처리 중인 문서를 반환합니다.
CONCAT 유형이 동일한 두 개 이상의 값을 연결합니다.
LENGTH String, Bytes, Array, Vector 또는 Map의 길이를 계산합니다.
REVERSE String, Bytes 또는 Array를 반전합니다.

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"))
자바
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

설명:

String, Bytes, Array, Vector 또는 Map 값의 길이를 계산합니다.

예:

length(value)
"hello" 5
[1, 2, 3, 4] 4
b"abcde" 5
null null
1 오류

REVERSE

구문:

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

설명:

String, Bytes 또는 Array 값을 반전합니다.

예:

reverse(value)
"hello" "olleh"
[1, 2, 3] [3, 2, 1]
b"abc" b"cba"
23 오류
null null

다음 단계