الدوال العامة

الدوال العامة

الاسم الوصف
CURRENT_DOCUMENT تعرض المستند الذي تتم معالجته حاليًا في خط النقل.
CONCAT تدمج قيمتَين أو أكثر من النوع نفسه.
LENGTH تحسب طول String أو Bytes أو Array أو Vector أو Map.
REVERSE تعكس ترتيب String أو Bytes أو Array.

CURRENT_DOCUMENT

البنية:

current_document() -> MAP

Description:

تؤدي هذه الدالة إلى عرض خريطة تتضمّن جميع الحقول المحدّدة في النطاق الحالي. ويكون ذلك مفيدًا عند دمج مستندات متعددة أو تجميعها معًا أو عند الرغبة في فحص أسماء الحقول في المستند بشكل ديناميكي.

على سبيل المثال، للحصول على قائمة بالمستندات المجمّعة حسب حقل معيّن:

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

Description:

تدمج قيمتَين أو أكثر من النوع نفسه.

Examples:

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

البنية:

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

Description:

تحسب طول قيمة String أو Bytes أو Array أو Vector أو Map.

Examples:

القيمة length(value)
"hello" 5
[1, 2, 3, 4] 4
b"abcde" 5
null null
1 خطأ

REVERSE

البنية:

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

Description:

تعكس ترتيب قيمة String أو Bytes أو Array.

Examples:

القيمة reverse(value)
"hello" "olleh"
[1, 2, 3] [3, 2, 1]
b"abc" b"cba"
23 خطأ
null null