ฟังก์ชันทั่วไป
| ชื่อ | คำอธิบาย |
CURRENT_DOCUMENT
|
แสดงผลเอกสารที่กำลังประมวลผลในไปป์ไลน์ |
CONCAT
|
เชื่อมต่อค่า 2 ค่าขึ้นไปที่มีประเภทเดียวกัน |
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
คำอธิบาย:
เชื่อมต่อค่า 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"));
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
ตัวอย่าง
| value | length(value) |
|---|---|
| "สวัสดี" | 5 |
| [1, 2, 3, 4] | 4 |
| b"abcde" | 5 |
| Null | Null |
| 1 | ข้อผิดพลาด |
ย้อนกลับ
ไวยากรณ์:
reverse[T <: STRING | BYTES | ARRAY](value: T) -> T
คำอธิบาย:
แสดงค่า String, Bytes หรือ Array แบบกลับกัน
ตัวอย่าง
| value | reverse(value) |
|---|---|
| "สวัสดี" | "olleh" |
| [1, 2, 3] | [3, 2, 1] |
| b"abc" | b"cba" |
| 23 | ข้อผิดพลาด |
| Null | Null |