פונקציות גנריות
| שם | תיאור |
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" | error |
| [1,2,3] | error |
| "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[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 | error |
הפוך
תחביר:
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 | error |
| null | null |