همه عملکردها، همه عملکردها

مصالح

تمام توابع تجمیعی می‌توانند به عنوان عبارات سطح بالا در مرحله aggregate(...) استفاده شوند.

نام توضیحات
COUNT تعداد اسناد را برمی‌گرداند.
COUNT_IF تعداد اسنادی را که در آنها یک عبارت به TRUE ارزیابی می‌شود، برمی‌گرداند.
COUNT_DISTINCT تعداد مقادیر منحصر به فرد و غیر NULL را برمی‌گرداند.
SUM مجموع تمام مقادیر NUMERIC را برمی‌گرداند
AVERAGE میانگین تمام مقادیر NUMERIC را برمی‌گرداند
MINIMUM حداقل مقدار غیر NULL را برمی‌گرداند
MAXIMUM حداکثر مقدار غیر NULL را برمی‌گرداند
FIRST مقدار expression را برای اولین سند برمی‌گرداند.
LAST مقدار expression را برای آخرین سند برمی‌گرداند.
ARRAY_AGG آرایه‌ای از تمام مقادیر ورودی را برمی‌گرداند.
ARRAY_AGG_DISTINCT آرایه‌ای از تمام مقادیر ورودی متمایز را برمی‌گرداند.

شمارش

نحو:

count() -> INT64
count(expression: ANY) -> INT64

شرح:

تعداد اسناد را از مرحله قبل که در expression به هر مقدار غیر NULL ارزیابی می‌شود، برمی‌گرداند. اگر هیچ expression ارائه نشده باشد، تعداد کل اسناد را از مرحله قبل برمی‌گرداند.

نود جی اس
// Total number of books in the collection
const countOfAll = await db.pipeline()
  .collection("books")
  .aggregate(countAll().as("count"))
  .execute();

// Number of books with nonnull `ratings` field
const countField = await db.pipeline()
  .collection("books")
  .aggregate(field("ratings").count().as("count"))
  .execute();

Web

// Total number of books in the collection
const countOfAll = await execute(db.pipeline()
  .collection("books")
  .aggregate(countAll().as("count"))
);

// Number of books with nonnull `ratings` field
const countField = await execute(db.pipeline()
  .collection("books")
  .aggregate(field("ratings").count().as("count"))
);
سویفت
// Total number of books in the collection
let countAll = try await db.pipeline()
  .collection("books")
  .aggregate([CountAll().as("count")])
  .execute()

// Number of books with nonnull `ratings` field
let countField = try await db.pipeline()
  .collection("books")
  .aggregate([Field("ratings").count().as("count")])
  .execute()

Kotlin

// Total number of books in the collection
val countAll = db.pipeline()
    .collection("books")
    .aggregate(AggregateFunction.countAll().alias("count"))
    .execute()

// Number of books with nonnull `ratings` field
val countField = db.pipeline()
    .collection("books")
    .aggregate(AggregateFunction.count("ratings").alias("count"))
    .execute()

Java

// Total number of books in the collection
Task<Pipeline.Snapshot> countAll = db.pipeline()
    .collection("books")
    .aggregate(AggregateFunction.countAll().alias("count"))
    .execute();

// Number of books with nonnull `ratings` field
Task<Pipeline.Snapshot> countField = db.pipeline()
    .collection("books")
    .aggregate(AggregateFunction.count("ratings").alias("count"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Count

# Total number of books in the collection
count_all = (
    client.pipeline().collection("books").aggregate(Count().as_("count")).execute()
)

# Number of books with nonnull `ratings` field
count_field = (
    client.pipeline()
    .collection("books")
    .aggregate(Count("ratings").as_("count"))
    .execute()
)
جاوا
// Total number of books in the collection
Pipeline.Snapshot countAll =
    firestore.pipeline().collection("books").aggregate(countAll().as("count")).execute().get();

// Number of books with nonnull `ratings` field
Pipeline.Snapshot countField =
    firestore
        .pipeline()
        .collection("books")
        .aggregate(count("ratings").as("count"))
        .execute()
        .get();

COUNT_IF

نحو:

count_if(expression: BOOLEAN) -> INT64

شرح:

تعداد اسناد را از مرحله قبلی که در expression به TRUE ارزیابی می‌شود، برمی‌گرداند.

نود جی اس
const result = await db.pipeline()
  .collection("books")
  .aggregate(
    field("rating").greaterThan(4).countIf().as("filteredCount")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .aggregate(
    field("rating").greaterThan(4).countIf().as("filteredCount")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .aggregate([
    AggregateFunction("count_if", [Field("rating").greaterThan(4)]).as("filteredCount")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .aggregate(
        AggregateFunction.countIf(field("rating").greaterThan(4)).alias("filteredCount")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .aggregate(
        AggregateFunction.countIf(field("rating").greaterThan(4)).alias("filteredCount")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .aggregate(Field.of("rating").greater_than(4).count_if().as_("filteredCount"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .aggregate(countIf(field("rating").greaterThan(4)).as("filteredCount"))
        .execute()
        .get();

تعداد متمایز

نحو:

count_distinct(expression: ANY) -> INT64

شرح:

تعداد مقادیر منحصر به فرد غیر NULL و غیر ABSENT از expression را برمی‌گرداند.

نود جی اس
const result = await db.pipeline()
  .collection("books")
  .aggregate(field("author").countDistinct().as("unique_authors"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .aggregate(field("author").countDistinct().as("unique_authors"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .aggregate([AggregateFunction("count_distinct", [Field("author")]).as("unique_authors")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .aggregate(AggregateFunction.countDistinct("author").alias("unique_authors"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .aggregate(AggregateFunction.countDistinct("author").alias("unique_authors"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .aggregate(Field.of("author").count_distinct().as_("unique_authors"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .aggregate(countDistinct("author").as("unique_authors"))
        .execute()
        .get();

جمع

نحو:

sum(expression: ANY) -> NUMBER

شرح:

مجموع تمام مقادیر عددی را برمی‌گرداند و مقادیر غیر عددی را نادیده می‌گیرد. اگر هر مقداری NaN باشد، NaN را برمی‌گرداند.

خروجی، به جز در این موارد، از همان نوع عریض‌ترین نوع ورودی برخوردار خواهد بود:

  • اگر نتوان یک INTEGER را به صورت INTEGER نمایش داد، آن نوع داده به DOUBLE تبدیل می‌شود.
نود جی اس
const result = await db.pipeline()
  .collection("cities")
  .aggregate(field("population").sum().as("totalPopulation"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("cities")
  .aggregate(field("population").sum().as("totalPopulation"))
);
سویفت
let result = try await db.pipeline()
  .collection("cities")
  .aggregate([Field("population").sum().as("totalPopulation")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("cities")
    .aggregate(AggregateFunction.sum("population").alias("totalPopulation"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("cities")
    .aggregate(AggregateFunction.sum("population").alias("totalPopulation"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("cities")
    .aggregate(Field.of("population").sum().as_("totalPopulation"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("cities")
        .aggregate(sum("population").as("totalPopulation"))
        .execute()
        .get();

میانگین

نحو:

average(expression: ANY) -> FLOAT64

شرح:

میانگین تمام مقادیر عددی را برمی‌گرداند و مقادیر غیرعددی را نادیده می‌گیرد. اگر هر مقداری NaN باشد، مقدار NaN و اگر هیچ مقدار عددی تجمیع نشده باشد، مقدار NULL را برمی‌گرداند.

خروجی، به جز در این موارد، از همان نوع ورودی خواهد بود:

  • اگر نتوان یک INTEGER را به صورت INTEGER نمایش داد، آن نوع داده به DOUBLE تبدیل می‌شود.
نود جی اس
const result = await db.pipeline()
  .collection("cities")
  .aggregate(field("population").average().as("averagePopulation"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("cities")
  .aggregate(field("population").average().as("averagePopulation"))
);
سویفت
let result = try await db.pipeline()
  .collection("cities")
  .aggregate([Field("population").average().as("averagePopulation")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("cities")
    .aggregate(AggregateFunction.average("population").alias("averagePopulation"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("cities")
    .aggregate(AggregateFunction.average("population").alias("averagePopulation"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("cities")
    .aggregate(Field.of("population").average().as_("averagePopulation"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("cities")
        .aggregate(average("population").as("averagePopulation"))
        .execute()
        .get();

حداقل

نحو:

minimum(expression: ANY) -> ANY

شرح:

حداقل مقدار غیر NULL و غیر غایب expression را هنگام ارزیابی روی هر سند برمی‌گرداند.

اگر هیچ مقداری غیر از NULL یا غیر غایب وجود نداشته باشد، NULL برگردانده می‌شود. این شامل زمانی که هیچ سندی در نظر گرفته نشده باشد نیز می‌شود.

اگر چندین مقدار حداقل معادل وجود داشته باشد، هر یک از آن مقادیر را می‌توان برگرداند. ترتیب نوع مقدار از ترتیب مستند پیروی می‌کند.

نود جی اس
const result = await db.pipeline()
  .collection("books")
  .aggregate(field("price").minimum().as("minimumPrice"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .aggregate(field("price").minimum().as("minimumPrice"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .aggregate([Field("price").minimum().as("minimumPrice")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .aggregate(AggregateFunction.minimum("price").alias("minimumPrice"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .aggregate(AggregateFunction.minimum("price").alias("minimumPrice"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .aggregate(Field.of("price").minimum().as_("minimumPrice"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .aggregate(minimum("price").as("minimumPrice"))
        .execute()
        .get();

حداکثر

نحو:

maximum(expression: ANY) -> ANY

شرح:

حداکثر مقدار غیر NULL و غیر غایب expression را هنگام ارزیابی روی هر سند برمی‌گرداند.

اگر هیچ مقداری غیر از NULL یا غیر غایب وجود نداشته باشد، NULL برگردانده می‌شود. این شامل زمانی که هیچ سندی در نظر گرفته نشده باشد نیز می‌شود.

اگر چندین مقدار حداکثر معادل وجود داشته باشد، هر یک از آن مقادیر را می‌توان برگرداند. ترتیب نوع مقدار از ترتیب مستند پیروی می‌کند.

نود جی اس
const result = await db.pipeline()
  .collection("books")
  .aggregate(field("price").maximum().as("maximumPrice"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .aggregate(field("price").maximum().as("maximumPrice"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .aggregate([Field("price").maximum().as("maximumPrice")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .aggregate(AggregateFunction.maximum("price").alias("maximumPrice"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .aggregate(AggregateFunction.maximum("price").alias("maximumPrice"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .aggregate(Field.of("price").maximum().as_("maximumPrice"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .aggregate(maximum("price").as("maximumPrice"))
        .execute()
        .get();

اول

نحو:

first(expression: ANY) -> ANY

شرح:

مقدار expression را برای اولین سند برگردانده شده برمی‌گرداند.

آخرین

نحو:

last(expression: ANY) -> ANY

شرح:

مقدار expression مربوط به آخرین سند برگردانده شده را برمی‌گرداند.

آرایه_AGG

نحو:

array_agg(expression: ANY) -> ARRAY<ANY>

شرح:

آرایه‌ای شامل تمام مقادیر expression را هنگام ارزیابی روی هر سند برمی‌گرداند.

اگر عبارت به یک مقدار غایب ختم شود، به NULL تبدیل می‌شود.

ترتیب عناصر در آرایه خروجی پایدار نیست و نباید به آن اعتماد کرد.

آرایه_AGG_متمایز

نحو:

array_agg_distinct(expression: ANY) -> ARRAY<ANY>

شرح:

آرایه‌ای شامل تمام مقادیر متمایز expression را هنگام ارزیابی روی هر سند برمی‌گرداند.

اگر عبارت به یک مقدار غایب ختم شود، به NULL تبدیل می‌شود.

ترتیب عناصر در آرایه خروجی پایدار نیست و نباید به آن اعتماد کرد.

توابع حسابی

تمام توابع حسابی در Cloud Firestore رفتارهای زیر را دارند:

  • اگر هر یک از پارامترهای ورودی NULL باشد، مقدار NULL را ارزیابی می‌کند.
  • اگر هر یک از آرگومان‌ها NaN باشد، مقدار NaN را ارزیابی می‌کند.
  • اگر سرریز یا سرریز ناقص رخ دهد، خطا ایجاد می‌کند.

علاوه بر این، هنگامی که یک تابع حسابی چندین آرگومان عددی از انواع مختلف را دریافت می‌کند (برای مثال: add(5.0, 6)Cloud Firestore به طور ضمنی آرگومان‌ها را به وسیع‌ترین نوع ورودی تبدیل می‌کند. اگر فقط ورودی‌های INT32 ارائه شوند، نوع بازگشتی INT64 خواهد بود.

نام توضیحات
ABS قدر مطلق یک number را برمی‌گرداند
ADD مقدار x + y را برمی‌گرداند
SUBTRACT مقدار x - y را برمی‌گرداند
MULTIPLY مقدار x * y را برمی‌گرداند
DIVIDE مقدار x / y را برمی‌گرداند
MOD باقیمانده تقسیم x / y را برمی‌گرداند
CEIL سقف یک number را برمی‌گرداند
FLOOR حداقل یک number را برمی‌گرداند
ROUND یک number تا places اعشار گرد می‌کند
TRUNC یک number تا places اعشار کوتاه می‌کند
POW مقدار base^exponent برمی‌گرداند
SQRT جذر یک number را برمی‌گرداند
EXP عدد اویلر را به توان exponent می‌رساند.
LN لگاریتم طبیعی یک number را برمی‌گرداند
LOG لگاریتم یک number را برمی‌گرداند
LOG10 لگاریتم یک number را در مبنای 10 برمی‌گرداند
RAND یک عدد اعشاری شبه تصادفی برمی‌گرداند

ای بی اس

نحو:

abs[N <: INT32 | INT64 | FLOAT64](number: N) -> N

شرح:

قدر مطلق یک number را برمی‌گرداند.

  • وقتی تابع مقدار INT32 یا INT64 را سرریز می‌کند، خطا می‌دهد.

مثال‌ها:

شماره abs(number)
۱۰ ۱۰
-10 ۱۰
10 لیتر 10 لیتر
-0.0 ۰.۰
۱۰.۵ ۱۰.۵
-۱۰.۵ ۱۰.۵
۳۱ [error]
۶۳ [error]

اضافه کردن

نحو:

add[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

شرح:

مقدار x + y را برمی‌گرداند.

مثال‌ها:

ایکس ی add(x, y)
۲۰ ۳ ۲۳
۱۰.۰ ۱ ۱۱.۰
۲۲.۵ ۲.۰ ۲۴.۵
INT64.MAX ۱ [error]
INT64.MIN -1 [error]
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("soldBooks").add(field("unsoldBooks")).as("totalBooks"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("soldBooks").add(field("unsoldBooks")).as("totalBooks"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("soldBooks").add(Field("unsoldBooks")).as("totalBooks")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(Expression.add(field("soldBooks"), field("unsoldBooks")).alias("totalBooks"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.add(field("soldBooks"), field("unsoldBooks")).alias("totalBooks"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("soldBooks").add(Field.of("unsoldBooks")).as_("totalBooks"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(add(field("soldBooks"), field("unsoldBooks")).as("totalBooks"))
        .execute()
        .get();

تفریق

نحو:

subtract[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

شرح:

مقدار x - y را برمی‌گرداند.

مثال‌ها:

ایکس ی subtract(x, y)
۲۰ ۳ ۱۷
۱۰.۰ ۱ ۹.۰
۲۲.۵ ۲.۰ ۲۰.۵
INT64.MAX -1 [error]
INT64.MIN ۱ [error]
نود جی اس
const storeCredit = 7;
const result = await db.pipeline()
  .collection("books")
  .select(field("price").subtract(constant(storeCredit)).as("totalCost"))
  .execute();

Web

const storeCredit = 7;
const result = await execute(db.pipeline()
  .collection("books")
  .select(field("price").subtract(constant(storeCredit)).as("totalCost"))
);
سویفت
let storeCredit = 7
let result = try await db.pipeline()
  .collection("books")
  .select([Field("price").subtract(Constant(storeCredit)).as("totalCost")])
  .execute()

Kotlin

val storeCredit = 7
val result = db.pipeline()
    .collection("books")
    .select(Expression.subtract(field("price"), storeCredit).alias("totalCost"))
    .execute()

Java

int storeCredit = 7;
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.subtract(field("price"), storeCredit).alias("totalCost"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

store_credit = 7
result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("price").subtract(store_credit).as_("totalCost"))
    .execute()
)
جاوا
int storeCredit = 7;
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(subtract(field("price"), storeCredit).as("totalCost"))
        .execute()
        .get();

ضرب کردن

نحو:

multiply[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

شرح:

مقدار x * y را برمی‌گرداند.

مثال‌ها:

ایکس ی multiply(x, y)
۲۰ ۳ ۶۰
۱۰.۰ ۱ ۱۰.۰
۲۲.۵ ۲.۰ ۴۵.۰
INT64.MAX ۲ [error]
INT64.MIN ۲ [error]
FLOAT64.MAX FLOAT64.MAX +inf
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("price").multiply(field("soldBooks")).as("revenue"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("price").multiply(field("soldBooks")).as("revenue"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("price").multiply(Field("soldBooks")).as("revenue")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(Expression.multiply(field("price"), field("soldBooks")).alias("revenue"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.multiply(field("price"), field("soldBooks")).alias("revenue"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("price").multiply(Field.of("soldBooks")).as_("revenue"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(multiply(field("price"), field("soldBooks")).as("revenue"))
        .execute()
        .get();

تقسیم کردن

نحو:

divide[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

شرح:

مقدار x / y را برمی‌گرداند. تقسیم عدد صحیح کوتاه شده است.

مثال‌ها:

ایکس ی divide(x, y)
۲۰ ۳ ۶
۱۰.۰ ۳ ۳.۳۳۳...
۲۲.۵ ۲ ۱۱.۲۵
۱۰ 0 [error]
۱.۰ ۰.۰ +inf
-۱.۰ ۰.۰ -inf
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("ratings").divide(field("soldBooks")).as("reviewRate"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("ratings").divide(field("soldBooks")).as("reviewRate"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("ratings").divide(Field("soldBooks")).as("reviewRate")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(Expression.divide(field("ratings"), field("soldBooks")).alias("reviewRate"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.divide(field("ratings"), field("soldBooks")).alias("reviewRate"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("ratings").divide(Field.of("soldBooks")).as_("reviewRate"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(divide(field("ratings"), field("soldBooks")).as("reviewRate"))
        .execute()
        .get();

وزارت دفاع

نحو:

mod[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

شرح:

باقیمانده x / y را برمی‌گرداند.

  • وقتی y برای انواع عدد صحیح ( INT64 ) صفر باشد، error می‌دهد.
  • وقتی y برای انواع اعشاری ( FLOAT64 ) صفر باشد، NaN را برمی‌گرداند.

مثال‌ها:

ایکس ی mod(x, y)
۲۰ ۳ ۲
-10 ۳ -1
۱۰ -3 ۱
-10 -3 -1
۱۰ ۱ 0
۲۲.۵ ۲ ۰.۵
۲۲.۵ ۰.۰ NaN
۲۵ 0 [error]
نود جی اس
const displayCapacity = 1000;
const result = await db.pipeline()
  .collection("books")
  .select(field("unsoldBooks").mod(constant(displayCapacity)).as("warehousedBooks"))
  .execute();

Web

const displayCapacity = 1000;
const result = await execute(db.pipeline()
  .collection("books")
  .select(field("unsoldBooks").mod(constant(displayCapacity)).as("warehousedBooks"))
);
سویفت
let displayCapacity = 1000
let result = try await db.pipeline()
  .collection("books")
  .select([Field("unsoldBooks").mod(Constant(displayCapacity)).as("warehousedBooks")])
  .execute()

Kotlin

val displayCapacity = 1000
val result = db.pipeline()
    .collection("books")
    .select(Expression.mod(field("unsoldBooks"), displayCapacity).alias("warehousedBooks"))
    .execute()

Java

int displayCapacity = 1000;
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.mod(field("unsoldBooks"), displayCapacity).alias("warehousedBooks"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

display_capacity = 1000
result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("unsoldBooks").mod(display_capacity).as_("warehousedBooks"))
    .execute()
)
جاوا
int displayCapacity = 1000;
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(mod(field("unsoldBooks"), displayCapacity).as("warehousedBooks"))
        .execute()
        .get();

سقف

نحو:

ceil[N <: INT32 | INT64 | FLOAT64](number: N) -> N

شرح:

کوچکترین مقدار صحیح که کمتر از number نباشد را برمی‌گرداند.

مثال‌ها:

شماره ceil(number)
۲۰ ۲۰
۱۰ ۱۰
0 0
۲۴ لیتر ۲۴ لیتر
-0.4 -0.0
۰.۴ ۱.۰
۲۲.۵ ۲۳.۰
+inf +inf
-inf -inf
نود جی اس
const booksPerShelf = 100;
const result = await db.pipeline()
  .collection("books")
  .select(
    field("unsoldBooks").divide(constant(booksPerShelf)).ceil().as("requiredShelves")
  )
  .execute();

Web

const booksPerShelf = 100;
const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("unsoldBooks").divide(constant(booksPerShelf)).ceil().as("requiredShelves")
  )
);
سویفت
let booksPerShelf = 100
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("unsoldBooks").divide(Constant(booksPerShelf)).ceil().as("requiredShelves")
  ])
  .execute()

Kotlin

val booksPerShelf = 100
val result = db.pipeline()
    .collection("books")
    .select(
        Expression.divide(field("unsoldBooks"), booksPerShelf).ceil().alias("requiredShelves")
    )
    .execute()

Java

int booksPerShelf = 100;
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        Expression.divide(field("unsoldBooks"), booksPerShelf).ceil().alias("requiredShelves")
    )
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

books_per_shelf = 100
result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("unsoldBooks")
        .divide(books_per_shelf)
        .ceil()
        .as_("requiredShelves")
    )
    .execute()
)
جاوا
int booksPerShelf = 100;
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(ceil(divide(field("unsoldBooks"), booksPerShelf)).as("requiredShelves"))
        .execute()
        .get();

طبقه

نحو:

floor[N <: INT32 | INT64 | FLOAT64](number: N) -> N

شرح:

بزرگترین مقدار صحیح که بزرگتر از number نباشد را برمی‌گرداند.

مثال‌ها:

شماره floor(number)
۲۰ ۲۰
۱۰ ۱۰
0 0
۲۱۴۷۴۸۳۶۴۸ ۲۱۴۷۴۸۳۶۴۸
-0.4 -۱.۰
۰.۴ ۰.۰
۲۲.۵ ۲۲.۰
+inf +inf
-inf -inf
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .addFields(
    field("wordCount").divide(field("pages")).floor().as("wordsPerPage")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .addFields(
    field("wordCount").divide(field("pages")).floor().as("wordsPerPage")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .addFields([
    Field("wordCount").divide(Field("pages")).floor().as("wordsPerPage")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .addFields(
        Expression.divide(field("wordCount"), field("pages")).floor().alias("wordsPerPage")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .addFields(
        Expression.divide(field("wordCount"), field("pages")).floor().alias("wordsPerPage")
    )
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .add_fields(
        Field.of("wordCount").divide(Field.of("pages")).floor().as_("wordsPerPage")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .addFields(floor(divide(field("wordCount"), field("pages"))).as("wordsPerPage"))
        .execute()
        .get();

گرد

نحو:

round[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N) -> N
round[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N, places: INT64) -> N

شرح:

places یک number را گرد می‌کند. اگر places مثبت باشد، ارقام را از سمت راست ممیز و اگر منفی باشد، ارقام را از سمت چپ ممیز گرد می‌کند.

  • اگر فقط number ارائه شده باشد، به نزدیکترین مقدار کامل گرد می‌شود.
  • در حالت‌های بینابینی، از صفر دور می‌شود.
  • اگر گرد کردن با places منفی منجر به سرریز شود، error رخ می‌دهد.

مثال‌ها:

شماره مکان‌ها round(number, places)
۱۵.۵ 0 ۱۶.۰
-۱۵.۵ 0 -۱۶.۰
۱۵ ۱ ۱۵
۱۵ 0 ۱۵
۱۵ -1 ۲۰
۱۵ 0
۱۵.۴۸۹۲۴ ۱ ۱۵.۵
۲ ۳۱ -1 [error]
۲ ۶۳ -۱ لیتر -1 [error]
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("soldBooks").multiply(field("price")).round().as("partialRevenue"))
  .aggregate(field("partialRevenue").sum().as("totalRevenue"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("soldBooks").multiply(field("price")).round().as("partialRevenue"))
  .aggregate(field("partialRevenue").sum().as("totalRevenue"))
  );
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("soldBooks").multiply(Field("price")).round().as("partialRevenue")])
  .aggregate([Field("partialRevenue").sum().as("totalRevenue")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(Expression.multiply(field("soldBooks"), field("price")).round().alias("partialRevenue"))
    .aggregate(AggregateFunction.sum("partialRevenue").alias("totalRevenue"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.multiply(field("soldBooks"), field("price")).round().alias("partialRevenue"))
    .aggregate(AggregateFunction.sum("partialRevenue").alias("totalRevenue"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("soldBooks")
        .multiply(Field.of("price"))
        .round()
        .as_("partialRevenue")
    )
    .aggregate(Field.of("partialRevenue").sum().as_("totalRevenue"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(round(multiply(field("soldBooks"), field("price"))).as("partialRevenue"))
        .aggregate(sum("partialRevenue").as("totalRevenue"))
        .execute()
        .get();

ترانک

نحو:

trunc[N <: Number](number: N) -> N
trunc[N <: Number](number:  N, places: INT64) -> N

شرح:

یک number تا تعداد مشخصی places اعشار کوتاه می‌کند. اگر places مثبت باشد، ارقام را از سمت راست ممیز و اگر منفی باشد، ارقام را از سمت چپ ممیز کوتاه می‌کند.

  • اگر فقط number ارائه شود، به نزدیکترین مقدار کامل به سمت صفر کوتاه می‌شود.
  • اگر کوتاه کردن منجر به سرریز شود، error رخ می‌دهد.

مثال‌ها:

شماره مکان‌ها trunc(number, places)
۱۵.۵ 0 ۱۵.۰
-۱۵.۵ 0 -۱۵.۰
۱۵ ۱ ۱۵
۱۵ 0 ۱۵
۱۵ -1 ۱۰
۱۵ 0
۱۵.۴۸۹۲۴ ۱ ۱۵.۴
‎-15.48924 ۲ -۱۵.۴۸

صدای انفجار

نحو:

pow(base: FLOAT64, exponent: FLOAT64) -> FLOAT64

شرح:

مقدار base را که به توان exponent رسیده است، برمی‌گرداند.

  • اگر base <= 0 و exponent منفی باشد، خطا می‌دهد.

  • برای هر exponent ، pow(1, exponent) برابر با ۱ است.

  • برای هر base ، pow(base, 0) برابر با ۱ است.

مثال‌ها:

پایه توان pow(base, exponent)
۲ ۳ ۸.۰
۲ -3 ۰.۱۲۵
+inf 0 ۱.۰
۱ +inf ۱.۰
-1 ۰.۵ [error]
0 -1 [error]
نود جی اس
const googleplex = { latitude: 37.4221, longitude: 122.0853 };
const result = await db.pipeline()
  .collection("cities")
  .addFields(
    field("lat").subtract(constant(googleplex.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("latitudeDifference"),
    field("lng").subtract(constant(googleplex.longitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("longitudeDifference")
  )
  .select(
    field("latitudeDifference").add(field("longitudeDifference")).sqrt()
      // Inaccurate for large distances or close to poles
      .as("approximateDistanceToGoogle")
  )
  .execute();

Web

const googleplex = { latitude: 37.4221, longitude: 122.0853 };
const result = await execute(db.pipeline()
  .collection("cities")
  .addFields(
    field("lat").subtract(constant(googleplex.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("latitudeDifference"),
    field("lng").subtract(constant(googleplex.longitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("longitudeDifference")
  )
  .select(
    field("latitudeDifference").add(field("longitudeDifference")).sqrt()
      // Inaccurate for large distances or close to poles
      .as("approximateDistanceToGoogle")
  )
);
سویفت
let googleplex = CLLocation(latitude: 37.4221, longitude: 122.0853)
let result = try await db.pipeline()
  .collection("cities")
  .addFields([
    Field("lat").subtract(Constant(googleplex.coordinate.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("latitudeDifference"),
    Field("lng").subtract(Constant(googleplex.coordinate.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("longitudeDifference")
  ])
  .select([
    Field("latitudeDifference").add(Field("longitudeDifference")).sqrt()
      // Inaccurate for large distances or close to poles
      .as("approximateDistanceToGoogle")
  ])
  .execute()

Kotlin

val googleplex = GeoPoint(37.4221, -122.0853)
val result = db.pipeline()
    .collection("cities")
    .addFields(
        field("lat").subtract(googleplex.latitude)
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("latitudeDifference"),
        field("lng").subtract(googleplex.longitude)
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("longitudeDifference")
    )
    .select(
        field("latitudeDifference").add(field("longitudeDifference")).sqrt()
            // Inaccurate for large distances or close to poles
            .alias("approximateDistanceToGoogle")
    )
    .execute()

Java

GeoPoint googleplex = new GeoPoint(37.4221, -122.0853);
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("cities")
    .addFields(
        field("lat").subtract(googleplex.getLatitude())
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("latitudeDifference"),
        field("lng").subtract(googleplex.getLongitude())
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("longitudeDifference")
    )
    .select(
        field("latitudeDifference").add(field("longitudeDifference")).sqrt()
            // Inaccurate for large distances or close to poles
            .alias("approximateDistanceToGoogle")
    )
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

googleplexLat = 37.4221
googleplexLng = -122.0853
result = (
    client.pipeline()
    .collection("cities")
    .add_fields(
        Field.of("lat")
        .subtract(googleplexLat)
        .multiply(111)  # km per degree
        .pow(2)
        .as_("latitudeDifference"),
        Field.of("lng")
        .subtract(googleplexLng)
        .multiply(111)  # km per degree
        .pow(2)
        .as_("longitudeDifference"),
    )
    .select(
        Field.of("latitudeDifference")
        .add(Field.of("longitudeDifference"))
        .sqrt()
        # Inaccurate for large distances or close to poles
        .as_("approximateDistanceToGoogle")
    )
    .execute()
)
جاوا
double googleplexLat = 37.4221;
double googleplexLng = -122.0853;
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("cities")
        .addFields(
            pow(multiply(subtract(field("lat"), googleplexLat), 111), 2)
                .as("latitudeDifference"),
            pow(multiply(subtract(field("lng"), googleplexLng), 111), 2)
                .as("longitudeDifference"))
        .select(
            sqrt(add(field("latitudeDifference"), field("longitudeDifference")))
                // Inaccurate for large distances or close to poles
                .as("approximateDistanceToGoogle"))
        .execute()
        .get();

اس کیو آر تی

نحو:

sqrt[N <: FLOAT64 | DECIMAL128](number: N) -> N

شرح:

جذر یک number را برمی‌گرداند.

  • اگر number منفی باشد، error می‌دهد.

مثال‌ها:

شماره sqrt(number)
۲۵ ۵.۰
۱۲.۰۰۲ ۳.۴۶۴...
۰.۰ ۰.۰
NaN NaN
+inf +inf
-inf [error]
x < 0 [error]
نود جی اس
const googleplex = { latitude: 37.4221, longitude: 122.0853 };
const result = await db.pipeline()
  .collection("cities")
  .addFields(
    field("lat").subtract(constant(googleplex.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("latitudeDifference"),
    field("lng").subtract(constant(googleplex.longitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("longitudeDifference")
  )
  .select(
    field("latitudeDifference").add(field("longitudeDifference")).sqrt()
      // Inaccurate for large distances or close to poles
      .as("approximateDistanceToGoogle")
  )
  .execute();

Web

const googleplex = { latitude: 37.4221, longitude: 122.0853 };
const result = await execute(db.pipeline()
  .collection("cities")
  .addFields(
    field("lat").subtract(constant(googleplex.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("latitudeDifference"),
    field("lng").subtract(constant(googleplex.longitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("longitudeDifference")
  )
  .select(
    field("latitudeDifference").add(field("longitudeDifference")).sqrt()
      // Inaccurate for large distances or close to poles
      .as("approximateDistanceToGoogle")
  )
);
سویفت
let googleplex = CLLocation(latitude: 37.4221, longitude: 122.0853)
let result = try await db.pipeline()
  .collection("cities")
  .addFields([
    Field("lat").subtract(Constant(googleplex.coordinate.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("latitudeDifference"),
    Field("lng").subtract(Constant(googleplex.coordinate.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("longitudeDifference")
  ])
  .select([
    Field("latitudeDifference").add(Field("longitudeDifference")).sqrt()
      // Inaccurate for large distances or close to poles
      .as("approximateDistanceToGoogle")
  ])
  .execute()

Kotlin

val googleplex = GeoPoint(37.4221, -122.0853)
val result = db.pipeline()
    .collection("cities")
    .addFields(
        field("lat").subtract(googleplex.latitude)
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("latitudeDifference"),
        field("lng").subtract(googleplex.longitude)
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("longitudeDifference")
    )
    .select(
        field("latitudeDifference").add(field("longitudeDifference")).sqrt()
            // Inaccurate for large distances or close to poles
            .alias("approximateDistanceToGoogle")
    )
    .execute()

Java

GeoPoint googleplex = new GeoPoint(37.4221, -122.0853);
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("cities")
    .addFields(
        field("lat").subtract(googleplex.getLatitude())
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("latitudeDifference"),
        field("lng").subtract(googleplex.getLongitude())
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("longitudeDifference")
    )
    .select(
        field("latitudeDifference").add(field("longitudeDifference")).sqrt()
            // Inaccurate for large distances or close to poles
            .alias("approximateDistanceToGoogle")
    )
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

googleplexLat = 37.4221
googleplexLng = -122.0853
result = (
    client.pipeline()
    .collection("cities")
    .add_fields(
        Field.of("lat")
        .subtract(googleplexLat)
        .multiply(111)  # km per degree
        .pow(2)
        .as_("latitudeDifference"),
        Field.of("lng")
        .subtract(googleplexLng)
        .multiply(111)  # km per degree
        .pow(2)
        .as_("longitudeDifference"),
    )
    .select(
        Field.of("latitudeDifference")
        .add(Field.of("longitudeDifference"))
        .sqrt()
        # Inaccurate for large distances or close to poles
        .as_("approximateDistanceToGoogle")
    )
    .execute()
)
جاوا
double googleplexLat = 37.4221;
double googleplexLng = -122.0853;
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("cities")
        .addFields(
            pow(multiply(subtract(field("lat"), googleplexLat), 111), 2)
                .as("latitudeDifference"),
            pow(multiply(subtract(field("lng"), googleplexLng), 111), 2)
                .as("longitudeDifference"))
        .select(
            sqrt(add(field("latitudeDifference"), field("longitudeDifference")))
                // Inaccurate for large distances or close to poles
                .as("approximateDistanceToGoogle"))
        .execute()
        .get();

تاریخ انقضا

نحو:

exp(exponent: FLOAT64) -> FLOAT64

شرح:

مقدار عدد اویلر را که به توان exponent رسیده است، برمی‌گرداند. این تابع، تابع نمایی طبیعی نیز نامیده می‌شود.

مثال‌ها:

توان exp(exponent)
۰.۰ ۱.۰
۱۰ e^10 ( FLOAT64 )
+inf +inf
-inf 0
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("rating").exp().as("expRating"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").exp().as("expRating"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").exp().as("expRating")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("rating").exp().alias("expRating"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").exp().alias("expRating"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").exp().as_("expRating"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(exp(field("rating")).as("expRating"))
        .execute()
        .get();

ال ان

نحو:

ln(number: FLOAT64) -> FLOAT64

شرح:

لگاریتم طبیعی number را برمی‌گرداند. این تابع معادل تابع log(number) است.

مثال‌ها:

شماره ln(number)
۱ ۰.۰
۲ لیتر ۰.۶۹۳...
۱.۰ ۰.۰
e ( FLOAT64 ) ۱.۰
-inf NaN
+inf +inf
x <= 0 [error]
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("rating").ln().as("lnRating"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").ln().as("lnRating"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").ln().as("lnRating")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("rating").ln().alias("lnRating"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").ln().alias("lnRating"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").ln().as_("lnRating"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(ln(field("rating")).as("lnRating"))
        .execute()
        .get();

ورود به سیستم

نحو:

log(number: FLOAT64, base: FLOAT64) -> FLOAT64
log(number: FLOAT64) -> FLOAT64

شرح:

لگاریتم یک number را به base برمی‌گرداند.

  • اگر فقط number ارائه شده باشد، لگاریتم number را در base برمی‌گرداند (مترادف با ln(number) ).

مثال‌ها:

شماره پایه log(number, base)
۱۰۰ ۱۰ ۲.۰
-inf Numeric NaN
Numeric +inf NaN
number <= 0 Numeric [error]
Numeric base <= 0 [error]
Numeric ۱.۰ [error]

لاگ10

نحو:

log10(x: FLOAT64) -> FLOAT64

شرح:

لگاریتم یک number را در مبنای 10 برمی‌گرداند.

مثال‌ها:

شماره log10(number)
۱۰۰ ۲.۰
-inf NaN
+inf +inf
x <= 0 [error]

رند

نحو:

rand() -> FLOAT64

شرح:

یک عدد اعشاری شبه‌تصادفی را برمی‌گرداند که به طور یکنواخت بین 0.0 (شامل) و 1.0 (منحصراً) انتخاب شده است.

توابع آرایه

نام توضیحات
ARRAY یک ARRAY شامل یک عنصر برای هر آرگومان ورودی برمی‌گرداند
ARRAY_CONCAT چندین آرایه را به یک ARRAY واحد متصل می‌کند.
ARRAY_CONTAINS اگر ARRAY داده شده حاوی مقدار خاصی باشد TRUE را برمی‌گرداند.
ARRAY_CONTAINS_ALL اگر همه مقادیر در ARRAY وجود داشته باشند، TRUE برمی‌گرداند
ARRAY_CONTAINS_ANY اگر هر یک از مقادیر در ARRAY وجود داشته باشد، TRUE برمی‌گرداند
ARRAY_FILTER عناصری را از یک ARRAY که با یک گزاره مطابقت ندارند، فیلتر می‌کند.
ARRAY_FIRST اولین عنصر در یک ARRAY را برمی‌گرداند
ARRAY_FIRST_N n عنصر اول یک ARRAY را برمی‌گرداند。
ARRAY_GET عنصر موجود در یک اندیس مشخص در یک ARRAY را برمی‌گرداند.
ARRAY_INDEX_OF اندیس اولین رخداد یک مقدار در یک ARRAY را برمی‌گرداند。
ARRAY_INDEX_OF_ALL تمام اندیس‌های یک مقدار در یک ARRAY را برمی‌گرداند。
ARRAY_LENGTH تعداد عناصر موجود در یک ARRAY را برمی‌گرداند
ARRAY_LAST آخرین عنصر در یک ARRAY را برمی‌گرداند
ARRAY_LAST_N آخرین n عنصر در یک ARRAY را برمی‌گرداند。
ARRAY_REVERSE ترتیب عناصر یک ARRAY را معکوس می‌کند.
ARRAY_SLICE یک برش از یک ARRAY را برمی‌گرداند
ARRAY_TRANSFORM عناصر یک ARRAY را با اعمال عبارت به هر عنصر، تبدیل می‌کند.
MAXIMUM حداکثر مقدار را در یک ARRAY برمی‌گرداند。
MAXIMUM_N n تا از بزرگترین مقادیر موجود در یک ARRAY را برمی‌گرداند.
MINIMUM حداقل مقدار را در یک ARRAY برمی‌گرداند。
MINIMUM_N n تا از کوچکترین مقادیر موجود در یک ARRAY را برمی‌گرداند.
SUM مجموع تمام مقادیر NUMERIC موجود در یک ARRAY را برمی‌گرداند.
JOIN عناصر یک ARRAY را به صورت یک مقدار STRING به هم متصل می‌کند.

آرایه

نحو:

array(values: ANY...) -> ARRAY

شرح:

یک آرایه از عناصر داده شده می‌سازد.

  • اگر آرگومانی وجود نداشته باشد، در آرایه حاصل با NULL جایگزین می‌شود.

مثال‌ها:

ارزش‌ها array(values)
() []
(1، 2، 3) [1، 2، 3]
("الف"، 1، درست) ["الف"، 1، درست]
(1، تهی) [1، تهی]
(1، [2، 3]) [1، [2، 3]]

آرایه_کانکت

نحو:

array_concat(arrays: ARRAY...) -> ARRAY

شرح:

دو یا چند آرایه را در یک ARRAY واحد به هم متصل می‌کند.

مثال‌ها:

آرایه‌ها array_concat(arrays)
([1، 2]، [3، 4]) [1، 2، 3، 4]
(["الف"، "ب"]، ["ج"]) ["الف"، "ب"، "ج"]
([1]، [2]، [3]) [1، 2، 3]
([]، [1، 2]) [1، 2]
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("genre").arrayConcat([field("subGenre")]).as("allGenres"))
  .execute();
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("genre").arrayConcat([Field("subGenre")]).as("allGenres")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("genre").arrayConcat(field("subGenre")).alias("allGenres"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("genre").arrayConcat(field("subGenre")).alias("allGenres"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("genre").array_concat(Field.of("subGenre")).as_("allGenres"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(arrayConcat(field("genre"), field("subGenre")).as("allGenres"))
        .execute()
        .get();

محتویات آرایه

نحو:

array_contains(array: ARRAY, value: ANY) -> BOOLEAN

شرح:

اگر value در array یافت شود، TRUE و در غیر این صورت FALSE را برمی‌گرداند.

مثال‌ها:

آرایه ارزش array_contains(array, value)
[1، 2، 3] ۲ درست
[[1، 2]، [3]] [1، 2] درست
[1، تهی] تهی درست
"ای بی سی" هر خطا
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("genre").arrayContains(constant("mystery")).as("isMystery"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("genre").arrayContains(constant("mystery")).as("isMystery"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("genre").arrayContains(Constant("mystery")).as("isMystery")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("genre").arrayContains("mystery").alias("isMystery"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("genre").arrayContains("mystery").alias("isMystery"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("genre").array_contains("mystery").as_("isMystery"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(arrayContains(field("genre"), "mystery").as("isMystery"))
        .execute()
        .get();

آرایه شامل همه چیز است

نحو:

array_contains_all(array: ARRAY, search_values: ARRAY) -> BOOLEAN

شرح:

اگر همه search_values در array پیدا شوند، مقدار TRUE و در غیر این صورت FALSE برمی‌گرداند.

مثال‌ها:

آرایه مقادیر_جستجو array_contains_all(array, search_values)
[1، 2، 3] [1، 2] درست
[1، 2، 3] [1، 4] نادرست
[1، تهی] [تهی] درست
[نان] [نان] درست
[] [] درست
[1، 2، 3] [] درست
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    field("genre")
      .arrayContainsAll([constant("fantasy"), constant("adventure")])
      .as("isFantasyAdventure")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("genre")
      .arrayContainsAll([constant("fantasy"), constant("adventure")])
      .as("isFantasyAdventure")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("genre")
      .arrayContainsAll([Constant("fantasy"), Constant("adventure")])
      .as("isFantasyAdventure")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("genre")
            .arrayContainsAll(listOf("fantasy", "adventure"))
            .alias("isFantasyAdventure")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("genre")
            .arrayContainsAll(Arrays.asList("fantasy", "adventure"))
            .alias("isFantasyAdventure")
    )
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("genre")
        .array_contains_all(["fantasy", "adventure"])
        .as_("isFantasyAdventure")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(
            arrayContainsAll(field("genre"), Arrays.asList("fantasy", "adventure"))
                .as("isFantasyAdventure"))
        .execute()
        .get();

آرایه شامل هر چیزی است

نحو:

array_contains_any(array: ARRAY, search_values: ARRAY) -> BOOLEAN

شرح:

اگر هر یک از مقادیر search_values در array یافت شود، مقدار TRUE و در غیر این صورت FALSE برمی‌گرداند.

مثال‌ها:

آرایه مقادیر_جستجو array_contains_any(array, search_values)
[1، 2، 3] [4، 1] درست
[1، 2، 3] [4، 5] نادرست
[1، 2، تهی] [تهی] درست
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    field("genre")
      .arrayContainsAny([constant("fantasy"), constant("nonfiction")])
      .as("isMysteryOrFantasy")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("genre")
      .arrayContainsAny([constant("fantasy"), constant("nonfiction")])
      .as("isMysteryOrFantasy")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("genre")
      .arrayContainsAny([Constant("fantasy"), Constant("nonfiction")])
      .as("isMysteryOrFantasy")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("genre")
            .arrayContainsAny(listOf("fantasy", "nonfiction"))
            .alias("isMysteryOrFantasy")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("genre")
            .arrayContainsAny(Arrays.asList("fantasy", "nonfiction"))
            .alias("isMysteryOrFantasy")
    )
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("genre")
        .array_contains_any(["fantasy", "nonfiction"])
        .as_("isMysteryOrFantasy")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(
            arrayContainsAny(field("genre"), Arrays.asList("fantasy", "nonfiction"))
                .as("isMysteryOrFantasy"))
        .execute()
        .get();

فیلتر آرایه

نحو:

array_filter(array: ARRAY, predicate: (ANY) -> BOOLEAN) -> ARRAY

شرح:

array با استفاده از یک عبارت predicate فیلتر می‌کند و یک آرایه جدید با عناصری که فقط با عبارت محمولی مطابقت دارند، برمی‌گرداند.

  • برای هر عنصر در array ، predicate ارزیابی می‌شود. اگر مقدار true را برگرداند، عنصر در نتیجه گنجانده می‌شود؛ در غیر این صورت (اگر false یا null را برگرداند)، حذف می‌شود.
  • اگر مقدار گزاره predicate غیر بولی یا غیر تهی (non-null) باشد، تابع خطا برمی‌گرداند.

مثال‌ها:

آرایه گزاره array_filter(array, predicate)
[1، 2، 3] ایکس -> ایکس > ۱ [2، 3]
[1، تهی، 3] ایکس -> ایکس > ۱ [3]
["الف"، "ب"، "ج"] x -> x != "b" ["الف"، "ج"]
[] ایکس -> درست []

آرایه_دریافت

نحو:

array_get(array: ARRAY, index: INT64) -> ANY

شرح:

عنصری را که در index مبتنی بر 0 در array قرار دارد، برمی‌گرداند.

  • اگر index منفی باشد، عناصر از انتهای آرایه قابل دسترسی هستند، که در آن -1 آخرین عنصر است.
  • اگر array از نوع ARRAY و null نباشد، خطا برمی‌گرداند.
  • اگر index خارج از محدوده باشد، تابع مقداری را برمی‌گرداند که وجود ندارد.
  • اگر index از نوع INT64 نباشد، تابع خطا برمی‌گرداند.

مثال‌ها:

آرایه شاخص array_get(array, index)
[1، 2، 3] 0 ۱
[1، 2، 3] -1 ۳
[1، 2، 3] ۳ غایب
[1، 2، 3] -4 غایب
"ای بی سی" 0 خطا
تهی 0 تهی
Array «الف» خطا
Array ۲.۰ خطا

طول آرایه

نحو:

array_length(array: ARRAY) -> INT64

شرح:

تعداد عناصر موجود در array را برمی‌گرداند.

مثال‌ها:

آرایه array_length(array)
[1، 2، 3] ۳
[] 0
[1، 1، 1] ۳
[1، تهی] ۲
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("genre").arrayLength().as("genreCount"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("genre").arrayLength().as("genreCount"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("genre").arrayLength().as("genreCount")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("genre").arrayLength().alias("genreCount"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("genre").arrayLength().alias("genreCount"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("genre").array_length().as_("genreCount"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(arrayLength(field("genre")).as("genreCount"))
        .execute()
        .get();

معکوس آرایه

نحو:

array_reverse(array: ARRAY) -> ARRAY

شرح:

array داده شده را معکوس می‌کند.

مثال‌ها:

آرایه array_reverse(array)
[1، 2، 3] [3، 2، 1]
["الف"، "ب"] ["ب"، "الف"]
[1، 2، 2، 3] [3، 2، 2، 1]
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(arrayReverse(field("genre")).as("reversedGenres"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("genre").arrayReverse().as("reversedGenres"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("genre").arrayReverse().as("reversedGenres")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("genre").arrayReverse().alias("reversedGenres"))
    .execute()
    

Java

Task<Pipeline.Snapshot> result = db.pipeline() .collection("books") .select(field("genre").arrayReverse().alias("reversedGenres")) .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("genre").array_reverse().as_("reversedGenres"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(arrayReverse(field("genre")).as("reversedGenres"))
        .execute()
        .get();

آرایه اول

نحو:

array_first(array: ARRAY) -> ANY

شرح:

اولین عنصر array را برمی‌گرداند. این معادل array_get(array, 0) است.

  • اگر array خالی باشد، مقداری که وجود ندارد را برمی‌گرداند.

مثال‌ها:

آرایه array_first(array)
[1، 2، 3] ۱
[] غایب

آرایه اول

نحو:

array_first_n(array: ARRAY, n: INT64) -> ARRAY

شرح:

n عنصر اول array را برمی‌گرداند. این معادل array_slice(array, 0, n) است.

  • اگر n منفی باشد، خطا برمی‌گرداند.

مثال‌ها:

آرایه ن array_first_n(array, n)
[1، 2، 3، 4، 5] ۳ [1، 2، 3]
[1، 2] ۳ [1، 2]
[1، 2، 3] 0 []

آرایه_ایندکس_از

نحو:

array_index_of(array: ARRAY, value: ANY) -> INT64

شرح:

اندیس اولین رخداد value در array که بر اساس ۰ است را برمی‌گرداند. اگر value پیدا نشود، عدد -۱ را برمی‌گرداند.

مثال‌ها:

آرایه ارزش array_index_of(array, value)
[1، 2، 3، 2] ۲ ۱
[1، 2، 3] ۴ -1
[1، تهی، 3] تهی ۱

آرایه_فهرست_از_همه

نحو:

array_index_of_all(array: ARRAY, value: ANY) -> ARRAY<INT64>

شرح:

آرایه‌ای شامل اندیس‌های مبتنی بر صفرِ تمام تکرارهای value در array را برمی‌گرداند. اگر value پیدا نشود [] را برمی‌گرداند.

مثال‌ها:

آرایه ارزش array_index_of_all(array, value)
[1، 2، 3، 2] ۲ [1، 3]
[1، 2، 3] ۴ []
[1، تهی، 3، تهی] تهی [1، 3]

آخرین آرایه

نحو:

array_last(array: ARRAY) -> ANY

شرح:

آخرین عنصر array را برمی‌گرداند. این معادل array_get(array, -1) است.

  • اگر array خالی باشد، مقداری که وجود ندارد را برمی‌گرداند.

مثال‌ها:

آرایه array_last(array)
[1، 2، 3] ۳
[] غایب

آرایه_آخرین_شماره

نحو:

array_last_n(array: ARRAY, n: INT64) -> ARRAY

شرح:

آخرین n عنصر array را برمی‌گرداند.

  • اگر n منفی باشد، خطا برمی‌گرداند.

مثال‌ها:

آرایه ن array_last_n(array, n)
[1، 2، 3، 4، 5] ۳ [3، 4، 5]
[1، 2] ۳ [1، 2]
[1، 2، 3] 0 []

برش آرایه

نحو:

array_slice(array: ARRAY, offset: INT64, length: INT64) -> ARRAY

شرح:

زیرمجموعه‌ای از array که از offset اندیس مبتنی بر ۰ شروع می‌شود و شامل عناصر length است، برمی‌گرداند.

  • اگر offset منفی باشد، موقعیت شروع از انتهای آرایه را نشان می‌دهد، که -1 آخرین عنصر است.
  • اگر length بیشتر از تعداد عناصر باقی مانده در آرایه پس از offset باشد، نتیجه تا انتهای آرایه امتداد می‌یابد.
  • length باید غیر منفی باشد، در غیر این صورت خطا را برمی‌گرداند.

مثال‌ها:

آرایه جبران طول array_slice(array, offset, length)
[1، 2، 3، 4، 5] ۱ ۳ [2، 3، 4]
[1، 2، 3، 4، 5] ۲ [4، 5]
[1، 2، 3] ۱ ۵ [2، 3]
[1، 2، 3] ۳ ۲ []

تبدیل آرایه

نحو:

array_transform(array: ARRAY, expression: (ANY) -> ANY) -> ARRAY
array_transform(array: ARRAY, expression: (ANY, INT64) -> ANY) -> ARRAY

شرح:

با اعمال expression به هر عنصر، array تبدیل می‌کند و یک آرایه جدید با عناصر تبدیل‌شده را برمی‌گرداند. آرایه خروجی همیشه اندازه‌ای برابر با آرایه ورودی خواهد داشت.

  • expression می‌تواند یک تابع تکی باشد element -> result یا یک تابع دودویی (element, index) -> result .
  • اگر expression تکی باشد، با هر عنصر array فراخوانی می‌شود.
  • اگر expression دودویی باشد، با هر عنصر array و اندیس متناظر مبتنی بر 0 آن فراخوانی می‌شود.

مثال‌ها:

آرایه بیان array_transform(array, expression)
[1، 2، 3] ایکس -> ایکس * ۲ [2، 4، 6]
[1، 2، 3] ایکس -> ایکس + ۱ [2، 3، 4]
[10، 20] (x، i) -> x + i [10، 21]
[] ایکس -> ۱ []

حداکثر

نحو:

maximum(array: ARRAY) -> ANY

شرح:

حداکثر مقدار موجود در array را برمی‌گرداند.

  • مقادیر NULL در طول مقایسه نادیده گرفته می‌شوند.
  • اگر array خالی باشد یا فقط شامل مقادیر NULL باشد، NULL را برمی‌گرداند.

مثال‌ها:

آرایه maximum(array)
[1، 5، 2] ۵
[1، تهی، 5] ۵
["الف"، "ج"، "ب"] «سی»
[تهی، تهی] تهی
[] تهی

حداکثر_N

نحو:

maximum_n(array: ARRAY, n: INT64) -> ARRAY

شرح:

آرایه‌ای از n بزرگترین مقادیر موجود در array را به ترتیب نزولی برمی‌گرداند.

  • مقادیر NULL نادیده گرفته می‌شوند.
  • اگر n منفی باشد، خطا برمی‌گرداند.

مثال‌ها:

آرایه ن maximum_n(array, n)
[1، 5، 2، 4، 3] ۳ [5، 4، 3]
[1، تهی، 5] ۳ [5، 1]

حداقل

نحو:

minimum(array: ARRAY) -> ANY

شرح:

کمترین مقدار را در array برمی‌گرداند.

  • مقادیر NULL در طول مقایسه نادیده گرفته می‌شوند.
  • اگر array خالی باشد یا فقط شامل مقادیر NULL باشد، NULL را برمی‌گرداند.

مثال‌ها:

آرایه minimum(array)
[1، 5، 2] ۱
[5، تهی، 1] ۱
["الف"، "ج"، "ب"] «الف»
[تهی، تهی] تهی
[] تهی

حداقل تعداد

نحو:

minimum_n(array: ARRAY, n: INT64) -> ARRAY

شرح:

آرایه‌ای از n کوچکترین مقادیر موجود در array را به ترتیب صعودی برمی‌گرداند.

  • مقادیر NULL نادیده گرفته می‌شوند.
  • اگر n منفی باشد، خطا برمی‌گرداند.

مثال‌ها:

آرایه ن minimum_n(array, n)
[1، 5، 2، 4، 3] ۳ [1، 2، 3]
[5، تهی، 1] ۳ [1، 5]

جمع

نحو:

sum(array: ARRAY) -> INT64 | FLOAT64

شرح:

مجموع تمام مقادیر NUMERIC موجود در یک ARRAY را برمی‌گرداند.

  • مقادیر غیر عددی در آرایه نادیده گرفته می‌شوند.
  • اگر هر مقدار عددی در آرایه NaN باشد، تابع مقدار NaN را برمی‌گرداند.
  • نوع بازگشتی توسط وسیع‌ترین نوع عددی در آرایه تعیین می‌شود: INT64 < FLOAT64 .
  • اگر قبل از جمع کردن هر مقدار اعشاری، سرریز عدد صحیح ۶۴ بیتی رخ دهد، خطایی برگردانده می‌شود. اگر مقادیر اعشاری جمع شوند، سرریز منجر به بی‌نهایت +/- خواهد شد.
  • اگر آرایه اصلاً حاوی مقادیر عددی نباشد، تابع مقدار NULL را برمی‌گرداند.

مثال‌ها:

آرایه sum(array)
[1، 2، 3] 6 لیتر
[۱ لیتر، ۲ لیتر، ۳ لیتر] 6 لیتر
[2000000000، 2000000000] ۴۰۰۰۰۰۰۰۰۰لیتر
[10، 20.5] ۳۰.۵
[1، "الف"، 2] ۳ لیتر
[INT64.MAX_VALUE، ۱] خطا
[INT64.MAX_VALUE، ۱، -۱.۰] خطا
[INT64.MAX_VALUE، ۱.۰] ۹.۲۲۳۳۷۲۰۳۶۸۵۴۷۷۶e+۱۸

بپیوندید

نحو:

join[T <: STRING | BYTES](array: ARRAY<T>, delimiter: T) -> STRING
join[T <: STRING | BYTES](array: ARRAY<T>, delimiter: T, null_text: T) -> STRING

شرح:

مجموعه‌ای از عناصر array را به صورت STRING برمی‌گرداند. array می‌تواند از نوع داده STRING یا BYTES باشد.

  • تمام عناصر موجود در array ، delimiter و null_text باید از یک نوع باشند؛ همه آنها باید STRING یا همه BYTES باشند.
  • اگر null_text ارائه شود، هر مقدار NULL در array با null_text جایگزین می‌شود.
  • اگر null_text ارائه نشود، مقادیر NULL در array از نتیجه حذف می‌شوند.

مثال‌ها:

وقتی null_text ارائه نشود:

آرایه جداکننده join(array, delimiter)
["الف"، "ب"، "ج"] "،" «الف، ب، ج»
["الف"، تهی، "ج"] "،" «الف، ج»
[ب'آ'، ب'ب'، ب'ک'] ب'،' ب، ا، ب، ج
["الف"، ب'ج'] "،" خطا
["الف"، "ج"] ب'،' خطا
[ب'a'، ب'c'] "،" خطا

وقتی null_text ارائه می‌شود:

آرایه جداکننده متن_خالی join(array, delimiter, null_text)
["الف"، تهی، "ج"] "،" «گمشده» «الف، مفقود، ج»
[b'a'، تهی، b'c'] ب'،' پوچ ب'a، تهی، ج'
[تهی، "ب"، تهی] "،" «گمشده» «گمشده، ب، گم‌شده»
[b'a'، تهی، تهی] ب'،' پوچ بی، پوچ، پوچ
["الف"، تهی] "،" بی ان خطا
[b'a'، تهی] ب'،' «ن» خطا

توابع مقایسه

نام توضیحات
EQUAL مقایسه برابری
GREATER_THAN بزرگتر از مقایسه
GREATER_THAN_OR_EQUAL مقایسه بزرگتر یا مساوی
LESS_THAN کمتر از مقایسه
LESS_THAN_OR_EQUAL مقایسه کوچکتر یا مساوی
NOT_EQUAL مقایسه برابر نیست
CMP مقایسه کلی

برابر

نحو:

equal(x: ANY, y: ANY) -> BOOLEAN

مثال‌ها:

x y equal(x, y)
۱ لیتر ۱ لیتر TRUE
۱.۰ ۱ لیتر TRUE
-۱.۰ ۱ لیتر FALSE
نان ن نان ن TRUE
NULL NULL TRUE
NULL ABSENT FALSE

شرح:

اگر x و y برابر باشند، TRUE و در غیر این صورت FALSE برمی‌گرداند.

نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("rating").equal(5).as("hasPerfectRating"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").equal(5).as("hasPerfectRating"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").equal(5).as("hasPerfectRating")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("rating").equal(5).alias("hasPerfectRating"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").equal(5).alias("hasPerfectRating"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").equal(5).as_("hasPerfectRating"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(equal(field("rating"), 5).as("hasPerfectRating"))
        .execute()
        .get();

بزرگتر از

نحو:

greater_than(x: ANY, y: ANY) -> BOOLEAN

شرح:

اگر x از y بزرگتر باشد، TRUE و در غیر این صورت FALSE برمی‌گرداند.

اگر x و y قابل مقایسه نباشند، FALSE را برمی‌گرداند.

مثال‌ها:

x y greater_than(x, y)
۱ لیتر ۰.۰ TRUE
۱ لیتر ۱ لیتر FALSE
۱ لیتر ۲ لیتر FALSE
"فو" 0 لیتر FALSE
0 لیتر "فو" FALSE
نان ن 0 لیتر FALSE
0 لیتر نان ن FALSE
NULL NULL FALSE
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("rating").greaterThan(4).as("hasHighRating"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").greaterThan(4).as("hasHighRating"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").greaterThan(4).as("hasHighRating")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("rating").greaterThan(4).alias("hasHighRating"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").greaterThan(4).alias("hasHighRating"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").greater_than(4).as_("hasHighRating"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(greaterThan(field("rating"), 4).as("hasHighRating"))
        .execute()
        .get();

بزرگتر_از_یا_برابر

نحو:

greater_than_or_equal(x: ANY, y: ANY) -> BOOLEAN

شرح:

اگر x بزرگتر یا مساوی y باشد، TRUE و در غیر این صورت FALSE برمی‌گرداند.

اگر x و y قابل مقایسه نباشند، FALSE را برمی‌گرداند.

مثال‌ها:

x y greater_than_or_equal(x, y)
۱ لیتر ۰.۰ TRUE
۱ لیتر ۱ لیتر TRUE
۱ لیتر ۲ لیتر FALSE
"فو" 0 لیتر FALSE
0 لیتر "فو" FALSE
نان ن 0 لیتر FALSE
0 لیتر نان ن FALSE
NULL NULL TRUE
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("published").greaterThanOrEqual(1900).as("publishedIn20thCentury"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("published").greaterThanOrEqual(1900).as("publishedIn20thCentury"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("published").greaterThanOrEqual(1900).as("publishedIn20thCentury")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("published").greaterThanOrEqual(1900).alias("publishedIn20thCentury"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("published").greaterThanOrEqual(1900).alias("publishedIn20thCentury"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("published")
        .greater_than_or_equal(1900)
        .as_("publishedIn20thCentury")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(greaterThanOrEqual(field("published"), 1900).as("publishedIn20thCentury"))
        .execute()
        .get();

کمتر از

نحو:

less_than(x: ANY, y: ANY) -> BOOLEAN

شرح:

اگر x از y کوچکتر باشد، TRUE و در غیر این صورت FALSE برمی‌گرداند.

اگر x و y قابل مقایسه نباشند، FALSE را برمی‌گرداند.

مثال‌ها:

x y less_than(x, y)
۱ لیتر ۰.۰ FALSE
۱ لیتر ۱ لیتر FALSE
۱ لیتر ۲ لیتر TRUE
"فو" 0 لیتر FALSE
0 لیتر "فو" FALSE
نان ن 0 لیتر FALSE
0 لیتر نان ن FALSE
NULL NULL FALSE
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("published").lessThan(1923).as("isPublicDomainProbably"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("published").lessThan(1923).as("isPublicDomainProbably"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("published").lessThan(1923).as("isPublicDomainProbably")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("published").lessThan(1923).alias("isPublicDomainProbably"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("published").lessThan(1923).alias("isPublicDomainProbably"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("published").less_than(1923).as_("isPublicDomainProbably"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(lessThan(field("published"), 1923).as("isPublicDomainProbably"))
        .execute()
        .get();

کمتر یا مساوی

نحو:

less_than_or_equal(x: ANY, y: ANY) -> BOOLEAN

شرح:

اگر x کوچکتر یا مساوی y باشد، TRUE و در غیر این صورت FALSE برمی‌گرداند.

اگر x و y قابل مقایسه نباشند، FALSE را برمی‌گرداند.

مثال‌ها:

x y less_than(x, y)
۱ لیتر ۰.۰ FALSE
۱ لیتر ۱ لیتر TRUE
۱ لیتر ۲ لیتر TRUE
"فو" 0 لیتر FALSE
0 لیتر "فو" FALSE
نان ن 0 لیتر FALSE
0 لیتر نان ن FALSE
NULL NULL TRUE
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("rating").lessThanOrEqual(2).as("hasBadRating"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").lessThanOrEqual(2).as("hasBadRating"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").lessThanOrEqual(2).as("hasBadRating")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("rating").lessThanOrEqual(2).alias("hasBadRating"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").lessThanOrEqual(2).alias("hasBadRating"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").less_than_or_equal(2).as_("hasBadRating"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(lessThanOrEqual(field("rating"), 2).as("hasBadRating"))
        .execute()
        .get();

برابر نیست

نحو:

not_equal(x: ANY, y: ANY) -> BOOLEAN

شرح:

اگر x با y برابر نباشد، TRUE و در غیر این صورت FALSE برمی‌گرداند.

مثال‌ها:

x y not_equal(x, y)
۱ لیتر ۱ لیتر FALSE
۱.۰ ۱ لیتر FALSE
-۱.۰ ۱ لیتر TRUE
نان ن 0 لیتر TRUE
نان ن نان ن FALSE
NULL NULL FALSE
NULL ABSENT TRUE
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("title").notEqual("1984").as("not1984"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("title").notEqual("1984").as("not1984"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("title").notEqual("1984").as("not1984")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("title").notEqual("1984").alias("not1984"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("title").notEqual("1984").alias("not1984"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("title").not_equal("1984").as_("not1984"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(notEqual(field("title"), "1984").as("not1984"))
        .execute()
        .get();

سی ام پی

نحو:

cmp(x: ANY, y: ANY) -> Int64

شرح:

x و y را با هم مقایسه می‌کند و نتیجه زیر را برمی‌گرداند:

  • 1L اگر x از y بزرگتر باشد.
  • -1L اگر x کمتر از y باشد.
  • در غیر این صورت 0L .

برخلاف سایر توابع مقایسه، تابع cmp(...) برای انواع مختلف کار می‌کند و از همان ترتیبی که در مرحله sort(...) استفاده می‌شود، پیروی می‌کند. برای نحوه مرتب‌سازی مقادیر بین انواع مختلف، به ترتیب نوع مقدار مراجعه کنید.

مثال‌ها:

x y cmp(x, y)
۱ لیتر ۱ لیتر 0 لیتر
۱.۰ ۱ لیتر 0 لیتر
-۱.۰ ۱ لیتر -1 لیتر
۴۲.۵ دی "فو" -1 لیتر
NULL NULL 0 لیتر
NULL ABSENT 0 لیتر

توابع اشکال‌زدایی

نام توضیحات
EXISTS اگر مقدار، مقدار غایب نباشد، TRUE را برمی‌گرداند
IS_ABSENT اگر مقدار مورد نظر وجود نداشته باشد، TRUE برمی‌گرداند
IF_ABSENT اگر مقدار وجود نداشته باشد، آن را با یک عبارت جایگزین می‌کند
IS_ERROR دریافت و بررسی می‌کند که آیا خطایی توسط عبارت اصلی ایجاد شده است یا خیر.
IF_ERROR اگر خطایی رخ داده باشد، مقدار را با یک عبارت جایگزین می‌کند.
ERROR ارزیابی را خاتمه می‌دهد و خطایی را با پیام مشخص شده برمی‌گرداند

موجود است

نحو:

exists(value: ANY) -> BOOLEAN

شرح:

اگر value مقدار غایب نباشد، TRUE را برمی‌گرداند.

مثال‌ها:

value exists(value)
0 لیتر TRUE
"فو" TRUE
NULL TRUE
ABSENT FALSE
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("rating").exists().as("hasRating"))
  .execute();

Web

مثال:

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").exists().as("hasRating"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").exists().as("hasRating")])
  .execute()

Kotlin

مثال:

val result = db.pipeline()
    .collection("books")
    .select(field("rating").exists().alias("hasRating"))
    .execute()

Java

مثال:

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").exists().alias("hasRating"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").exists().as_("hasRating"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(exists(field("rating")).as("hasRating"))
        .execute()
        .get();

غایب است

نحو:

is_absent(value: ANY) -> BOOLEAN

شرح:

اگر value مقدار غایب باشد، مقدار TRUE و در غیر این صورت FALSE را برمی‌گرداند. مقادیر غایب، مقادیری هستند که در ورودی وجود ندارند، مانند یک فیلد سند که وجود ندارد.

مثال‌ها:

value is_absent(value)
0 لیتر FALSE
"فو" FALSE
NULL FALSE
ABSENT TRUE

اگر_غایب باشد

نحو:

if_absent(value: ANY, replacement: ANY) -> ANY

شرح:

اگر value یک مقدار وجود نداشته باشد، ارزیابی کرده و replacement را برمی‌گرداند. در غیر این صورت value را برمی‌گرداند.

مثال‌ها:

value replacement if_absent(value, replacement)
۵ لیتر 0 لیتر ۵ لیتر
NULL 0 لیتر NULL
ABSENT 0 لیتر 0 لیتر

خطای IS

نحو:

is_error(try: ANY) -> BOOLEAN

شرح:

اگر در حین ارزیابی try خطایی رخ دهد، TRUE برمی‌گرداند. در غیر این صورت، FALSE برمی‌گرداند.

اگر_خطا

نحو:

if_error(try: ANY, catch: ANY) -> ANY

شرح:

اگر در حین ارزیابی try خطایی رخ دهد، replacement ارزیابی و برمی‌گرداند. در غیر این صورت، مقدار حل‌شده try را برمی‌گرداند.

خطا

نحو:

error(message: STRING) -> ANY

شرح:

ارزیابی تابع error منجر به ارزیابی خط لوله برای خاتمه با یک خطا می‌شود. message داده شده در خطا گنجانده شده است.

مثال‌ها:

cond res switch_on(cond, res, error("no condition matched"))
TRUE ۱ لیتر ۱ لیتر
FALSE ۱ لیتر ERROR ("no condition matched")

توابع مرجع

نوع REFERENCE به عنوان یک "اشاره‌گر" به سایر اسناد موجود در پایگاه داده (یا حتی سایر پایگاه‌های داده) عمل می‌کند. توابع زیر امکان دستکاری این نوع را در حین اجرای پرس‌وجو فراهم می‌کنند.

نام توضیحات
COLLECTION_ID شناسه‌ی مجموعه‌ی برگ‌ها را در ارجاع داده شده برمی‌گرداند.
DOCUMENT_ID شناسه سند را در مرجع داده شده برمی‌گرداند.
PARENT مرجع والد را برمی‌گرداند
REFERENCE_SLICE زیرمجموعه‌ای از بخش‌های مرجع داده شده را برمی‌گرداند

شناسه مجموعه

نحو:

collection_id(ref: REFERENCE) -> STRING

شرح:

شناسه مجموعه برگ‌های REFERENCE داده شده را برمی‌گرداند.

مثال‌ها:

ref collection_id(ref)
users/user1 "users"
users/user1/posts/post1 "posts"

شناسه سند

نحو:

document_id(ref: REFERENCE) -> ANY

شرح:

شناسه سند مربوط به REFERENCE داده شده را برمی‌گرداند.

مثال‌ها:

ref document_id(ref)
users/user1 "user1"
users/user1/posts/post1 "post1"

والدین

نحو:

parent(ref: REFERENCE) -> REFERENCE

شرح:

REFERENCE والد مرجع داده شده را برمی‌گرداند، یا اگر مرجع از قبل یک مرجع ریشه باشد، NULL برمی‌گرداند.

مثال‌ها:

ref parent(ref)
/ NULL
users/user1 /
users/user1/posts/post1 users/user1

برش مرجع

نحو:

reference_slice(ref: REFERENCE, offset: INT, length: INT) -> REFERENCE

شرح:

یک REFERENCE (REFERENCE) لیستی از تاپل‌های (collection_id, document_id) است و این امکان را فراهم می‌کند تا نمایی از آن لیست را مشاهده کنید، درست مانند array_slice(...) .

یک REFERENCE جدید برمی‌گرداند که زیرمجموعه‌ای از بخش‌های ref داده شده است.

  • offset : اندیس شروع (مبتنی بر 0) برش. اگر منفی باشد، یک انحراف از انتهای ارجاع است.
  • length : تعداد بخش‌هایی که باید در برش گنجانده شوند.

مثال‌ها:

ref offset length reference_slice(ref, offset, length)
a/1/b/2/c/3 ۱ لیتر ۲ لیتر b/2/c/3
a/1/b/2/c/3 0 لیتر ۲ لیتر a/1/b/2
a/1/b/2/c/3 -2 لیتر ۲ لیتر c/3

توابع منطقی

نام توضیحات
AND یک AND منطقی انجام می‌دهد
OR یک OR منطقی انجام می‌دهد
XOR یک XOR منطقی انجام می‌دهد
NOT یک NOT منطقی انجام می‌دهد.
NOR یک NOR منطقی انجام می‌دهد.
CONDITIONAL ارزیابی شاخه‌ها بر اساس یک عبارت شرطی.
IF_NULL اولین مقدار غیر تهی را برمی‌گرداند
SWITCH_ON ارزیابی شعب بر اساس مجموعه‌ای از شرایط
EQUAL_ANY بررسی می‌کند که آیا یک مقدار با هر عنصری در آرایه برابر است یا خیر.
NOT_EQUAL_ANY بررسی می‌کند که آیا یک مقدار با هیچ یک از عناصر آرایه برابر نیست یا خیر.
MAXIMUM حداکثر مقدار را در مجموعه‌ای از مقادیر برمی‌گرداند
MINIMUM کمترین مقدار را در مجموعه‌ای از مقادیر برمی‌گرداند

و

نحو:

and(x: BOOLEAN...) -> BOOLEAN

شرح:

عملگر منطقی AND را برای دو یا چند مقدار بولی برمی‌گرداند.

اگر نتیجه به دلیل ABSENT یا NULL بودن هر یک از مقادیر داده شده قابل استخراج نباشد، NULL را برمی‌گرداند.

مثال‌ها:

x y and(x, y)
TRUE TRUE TRUE
FALSE TRUE FALSE
NULL TRUE NULL
ABSENT TRUE NULL
NULL FALSE FALSE
FALSE ABSENT FALSE
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    and(field("rating").greaterThan(4), field("price").lessThan(10))
      .as("under10Recommendation")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    and(field("rating").greaterThan(4), field("price").lessThan(10))
      .as("under10Recommendation")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    (Field("rating").greaterThan(4) && Field("price").lessThan(10))
      .as("under10Recommendation")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        Expression.and(field("rating").greaterThan(4),
          field("price").lessThan(10))
            .alias("under10Recommendation")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        Expression.and(
            field("rating").greaterThan(4),
            field("price").lessThan(10)
        ).alias("under10Recommendation")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field, And

result = (
    client.pipeline()
    .collection("books")
    .select(
        And(
            Field.of("rating").greater_than(4), Field.of("price").less_than(10)
        ).as_("under10Recommendation")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(
            and(greaterThan(field("rating"), 4), lessThan(field("price"), 10))
                .as("under10Recommendation"))
        .execute()
        .get();

یا

نحو:

or(x: BOOLEAN...) -> BOOLEAN

شرح:

OR منطقی دو یا چند مقدار بولی را برمی‌گرداند.

اگر نتیجه به دلیل ABSENT یا NULL بودن هر یک از مقادیر داده شده قابل استخراج نباشد، NULL را برمی‌گرداند.

مثال‌ها:

x y or(x, y)
TRUE TRUE TRUE
FALSE TRUE TRUE
NULL TRUE TRUE
ABSENT TRUE TRUE
NULL FALSE NULL
FALSE ABSENT NULL
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    or(field("genre").equal("Fantasy"), field("tags").arrayContains("adventure"))
      .as("matchesSearchFilters")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    or(field("genre").equal("Fantasy"), field("tags").arrayContains("adventure"))
      .as("matchesSearchFilters")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    (Field("genre").equal("Fantasy") || Field("tags").arrayContains("adventure"))
      .as("matchesSearchFilters")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        Expression.or(field("genre").equal("Fantasy"),
          field("tags").arrayContains("adventure"))
            .alias("matchesSearchFilters")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        Expression.or(
            field("genre").equal("Fantasy"),
            field("tags").arrayContains("adventure")
        ).alias("matchesSearchFilters")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field, And, Or

result = (
    client.pipeline()
    .collection("books")
    .select(
        Or(
            Field.of("genre").equal("Fantasy"),
            Field.of("tags").array_contains("adventure"),
        ).as_("matchesSearchFilters")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(
            or(equal(field("genre"), "Fantasy"), arrayContains(field("tags"), "adventure"))
                .as("matchesSearchFilters"))
        .execute()
        .get();

XOR

نحو:

xor(x: BOOLEAN...) -> BOOLEAN

شرح:

XOR منطقی دو یا چند مقدار بولی را برمی‌گرداند.

اگر هر یک از مقادیر داده شده ABSENT یا NULL باشند NULL را برمی‌گرداند.

مثال‌ها:

x y xor(x, y)
TRUE TRUE FALSE
FALSE FALSE FALSE
FALSE TRUE TRUE
NULL TRUE NULL
ABSENT TRUE NULL
NULL FALSE NULL
FALSE ABSENT NULL
نود جی اس
const result = await execute(db.pipeline()
  .collection("books")
  .select(
    xor(field("tags").arrayContains("magic"), field("tags").arrayContains("nonfiction"))
      .as("matchesSearchFilters")
  )
);

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    xor(field("tags").arrayContains("magic"), field("tags").arrayContains("nonfiction"))
      .as("matchesSearchFilters")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    (Field("tags").arrayContains("magic") ^ Field("tags").arrayContains("nonfiction"))
      .as("matchesSearchFilters")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        Expression.xor(field("tags").arrayContains("magic"),
          field("tags").arrayContains("nonfiction"))
            .alias("matchesSearchFilters")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        Expression.xor(
            field("tags").arrayContains("magic"),
            field("tags").arrayContains("nonfiction")
        ).alias("matchesSearchFilters")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field, Xor

result = (
    client.pipeline()
    .collection("books")
    .select(
        Xor(
            [
                Field.of("tags").array_contains("magic"),
                Field.of("tags").array_contains("nonfiction"),
            ]
        ).as_("matchesSearchFilters")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(
            xor(
                    arrayContains(field("tags"), "magic"),
                    arrayContains(field("tags"), "nonfiction"))
                .as("matchesSearchFilters"))
        .execute()
        .get();

نه

نحو:

nor(x: BOOLEAN...) -> BOOLEAN

شرح:

تابع NOR منطقی دو یا چند مقدار بولی را برمی‌گرداند.

اگر نتیجه به دلیل ABSENT یا NULL بودن هر یک از مقادیر داده شده قابل استخراج نباشد، NULL را برمی‌گرداند.

مثال‌ها:

x y nor(x, y)
TRUE TRUE FALSE
FALSE TRUE FALSE
FALSE FALSE TRUE
NULL TRUE FALSE
ABSENT TRUE FALSE
NULL FALSE NULL
FALSE ABSENT NULL

نه

نحو:

not(x: BOOLEAN) -> BOOLEAN

شرح:

مقدار منطقی NOT یک مقدار بولی را برمی‌گرداند.

نود جی اس
const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("tags").arrayContains("nonfiction").not()
      .as("isFiction")
  )
);

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("tags").arrayContains("nonfiction").not()
      .as("isFiction")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    (!Field("tags").arrayContains("nonfiction"))
      .as("isFiction")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        Expression.not(
            field("tags").arrayContains("nonfiction")
        ).alias("isFiction")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        Expression.not(
            field("tags").arrayContains("nonfiction")
        ).alias("isFiction")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field, Not

result = (
    client.pipeline()
    .collection("books")
    .select(Not(Field.of("tags").array_contains("nonfiction")).as_("isFiction"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(not(arrayContains(field("tags"), "nonfiction")).as("isFiction"))
        .execute()
        .get();

مشروط

نحو:

conditional(condition: BOOLEAN, true_case: ANY, false_case: ANY) -> ANY

شرح:

اگر condition TRUE باشد، true_case را ارزیابی کرده و برمی‌گرداند.

اگر شرط به FALSE ، NULL یا مقدار ABSENT ختم شود، false_case ارزیابی کرده و برمی‌گرداند.

مثال‌ها:

condition true_case false_case conditional(condition, true_case, false_case)
TRUE ۱ لیتر 0 لیتر ۱ لیتر
FALSE ۱ لیتر 0 لیتر 0 لیتر
NULL ۱ لیتر 0 لیتر 0 لیتر
ABSENT ۱ لیتر 0 لیتر 0 لیتر
نود جی اس
const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("tags").arrayConcat([
      field("pages").greaterThan(100)
        .conditional(constant("longRead"), constant("shortRead"))
    ]).as("extendedTags")
  )
);

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("tags").arrayConcat([
      field("pages").greaterThan(100)
        .conditional(constant("longRead"), constant("shortRead"))
    ]).as("extendedTags")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("tags").arrayConcat([
      ConditionalExpression(
        Field("pages").greaterThan(100),
        then: Constant("longRead"),
        else: Constant("shortRead")
      )
    ]).as("extendedTags")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("tags").arrayConcat(
            Expression.conditional(
                field("pages").greaterThan(100),
                constant("longRead"),
                constant("shortRead")
            )
        ).alias("extendedTags")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("tags").arrayConcat(
            Expression.conditional(
                field("pages").greaterThan(100),
                constant("longRead"),
                constant("shortRead")
            )
        ).alias("extendedTags")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import (
    Field,
    Constant,
    Conditional,
)

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("tags")
        .array_concat(
            Conditional(
                Field.of("pages").greater_than(100),
                Constant.of("longRead"),
                Constant.of("shortRead"),
            )
        )
        .as_("extendedTags")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(
            arrayConcat(
                    field("tags"),
                    conditional(
                        greaterThan(field("pages"), 100),
                        constant("longRead"),
                        constant("shortRead")))
                .as("extendedTags"))
        .execute()
        .get();

اگر_NULL

نحو:

if_null(expr: ANY, replacement: ANY) -> ANY

شرح:

اگر NULL نباشد، expr برمی‌گرداند، در غیر این صورت ارزیابی کرده و replacement را برمی‌گرداند. اگر expr استفاده شود، عبارت replacement ارزیابی نمی‌شود.

مثال‌ها:

expr replacement if_null(expr, replacement)
۱ لیتر ۲ لیتر ۱ لیتر
NULL ۲ لیتر ۲ لیتر
ABSENT ۲ لیتر ABSENT

روشن کردن

نحو:

switch_on(cond1: BOOLEAN, res1: ANY, cond2: BOOLEAN, res2: ANY, ..., [default: ANY]) -> ANY

شرح:

یک سری شرط را ارزیابی می‌کند و نتیجه‌ی مرتبط با اولین شرط TRUE را برمی‌گرداند. اگر هیچ شرطی TRUE نباشد، مقدار default در صورت ارائه شدن بازگردانده می‌شود. اگر مقدار default ارائه نشود، اگر هیچ شرط دیگری TRUE ارزیابی نشود، خطایی رخ می‌دهد.

برای ارائه یک مقدار default ، آن را به عنوان آرگومان نهایی ارسال کنید، به طوری که تعداد آرگومان‌ها فرد باشد.

مثال‌ها:

x switch_on(eq(x, 1L), "one", eq(x, 2L), "two", "other")
۱ لیتر «یک»
۲ لیتر «دو»
۳ لیتر «دیگر»

مساوی_هر

نحو:

equal_any(value: ANY, search_space: ARRAY) -> BOOLEAN

شرح:

اگر value در آرایه search_space باشد، TRUE برمی‌گرداند.

مثال‌ها:

value search_space equal_any(value, search_space)
0 لیتر [۱ لیتر، ۲ لیتر، ۳ لیتر] FALSE
۲ لیتر [۱ لیتر، ۲ لیتر، ۳ لیتر] TRUE
NULL [۱ لیتر، ۲ لیتر، ۳ لیتر] FALSE
NULL [1L، NULL ] TRUE
ABSENT [1L، NULL ] FALSE
نان ن [1 لیتر، NaN، 3 لیتر] TRUE
نود جی اس
const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("genre").equalAny(["Science Fiction", "Psychological Thriller"])
      .as("matchesGenreFilters")
  )
);

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("genre").equalAny(["Science Fiction", "Psychological Thriller"])
      .as("matchesGenreFilters")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("genre").equalAny(["Science Fiction", "Psychological Thriller"])
      .as("matchesGenreFilters")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("genre").equalAny(listOf("Science Fiction", "Psychological Thriller"))
            .alias("matchesGenreFilters")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("genre").equalAny(Arrays.asList("Science Fiction", "Psychological Thriller"))
            .alias("matchesGenreFilters")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("genre")
        .equal_any(["Science Fiction", "Psychological Thriller"])
        .as_("matchesGenreFilters")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(
            equalAny(field("genre"), Arrays.asList("Science Fiction", "Psychological Thriller"))
                .as("matchesGenreFilters"))
        .execute()
        .get();

برابر نیست

نحو:

not_equal_any(value: ANY, search_space: ARRAY) -> BOOLEAN

شرح:

اگر value در آرایه search_space نباشد، TRUE برمی‌گرداند.

مثال‌ها:

value search_space not_equal_any(value, search_space)
0 لیتر [۱ لیتر، ۲ لیتر، ۳ لیتر] TRUE
۲ لیتر [۱ لیتر، ۲ لیتر، ۳ لیتر] FALSE
NULL [۱ لیتر، ۲ لیتر، ۳ لیتر] TRUE
NULL [1L، NULL ] FALSE
ABSENT [1L، NULL ] TRUE
نان ن [1 لیتر، NaN، 3 لیتر] FALSE
نود جی اس
const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("author").notEqualAny(["George Orwell", "F. Scott Fitzgerald"])
      .as("byExcludedAuthors")
  )
);

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("author").notEqualAny(["George Orwell", "F. Scott Fitzgerald"])
      .as("byExcludedAuthors")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("author").notEqualAny(["George Orwell", "F. Scott Fitzgerald"])
      .as("byExcludedAuthors")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("author").notEqualAny(listOf("George Orwell", "F. Scott Fitzgerald"))
            .alias("byExcludedAuthors")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("author").notEqualAny(Arrays.asList("George Orwell", "F. Scott Fitzgerald"))
            .alias("byExcludedAuthors")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("author")
        .not_equal_any(["George Orwell", "F. Scott Fitzgerald"])
        .as_("byExcludedAuthors")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(
            notEqualAny(field("author"), Arrays.asList("George Orwell", "F. Scott Fitzgerald"))
                .as("byExcludedAuthors"))
        .execute()
        .get();

حداکثر

نحو:

maximum(x: ANY...) -> ANY
maximum(x: ARRAY) -> ANY

شرح:

حداکثر مقدار غیر NULL و غیر ABSENT را در یک سری از مقادیر x برمی‌گرداند.

اگر هیچ مقداری غیر از NULL و غیر از ABSENT وجود نداشته باشد، NULL بازگردانده می‌شود.

اگر چندین مقدار حداکثر معادل وجود داشته باشد، هر یک از آن مقادیر را می‌توان برگرداند. ترتیب نوع مقدار از ترتیب مستند پیروی می‌کند.

مثال‌ها:

x y maximum(x, y)
FALSE TRUE TRUE
FALSE -10 لیتر -10 لیتر
۰.۰ -5 لیتر ۰.۰
"فو" "بار" "فو"
"فو" ["غذا"] ["غذا"]
ABSENT ABSENT NULL
NULL NULL NULL
نود جی اس
const result = await execute(db.pipeline()
  .collection("books")
  .aggregate(field("price").maximum().as("maximumPrice"))
);

Web

const result = await execute(db.pipeline()
  .collection("books")
  .aggregate(field("price").maximum().as("maximumPrice"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("rating").logicalMaximum([1]).as("flooredRating")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("rating").logicalMaximum(1).alias("flooredRating")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("rating").logicalMaximum(1).alias("flooredRating")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").logical_maximum(1).as_("flooredRating"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(logicalMaximum(field("rating"), 1).as("flooredRating"))
        .execute()
        .get();

حداقل

نحو:

minimum(x: ANY...) -> ANY
minimum(x: ARRAY) -> ANY

شرح:

کمترین مقدار غیر NULL و غیر ABSENT را در یک سری از مقادیر x برمی‌گرداند.

اگر هیچ مقداری غیر از NULL و غیر از ABSENT وجود نداشته باشد، NULL بازگردانده می‌شود.

اگر چندین مقدار حداقل معادل وجود داشته باشد، هر یک از آن مقادیر را می‌توان برگرداند. ترتیب نوع مقدار از ترتیب مستند پیروی می‌کند.

مثال‌ها:

x y minimum(x, y)
FALSE TRUE FALSE
FALSE -10 لیتر FALSE
۰.۰ -5 لیتر -5 لیتر
"فو" "بار" "بار"
"فو" ["غذا"] "فو"
ABSENT ABSENT NULL
NULL NULL NULL
نود جی اس
const result = await execute(db.pipeline()
  .collection("books")
  .aggregate(field("price").minimum().as("minimumPrice"))
);

Web

const result = await execute(db.pipeline()
  .collection("books")
  .aggregate(field("price").minimum().as("minimumPrice"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("rating").logicalMinimum([5]).as("cappedRating")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("rating").logicalMinimum(5).alias("cappedRating")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("rating").logicalMinimum(5).alias("cappedRating")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").logical_minimum(5).as_("cappedRating"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(logicalMinimum(field("rating"), 5).as("cappedRating"))
        .execute()
        .get();

توابع نقشه

نام توضیحات
MAP یک مقدار نگاشت (map value) را از مجموعه‌ای از جفت‌های کلید-مقدار می‌سازد.
MAP_GET مقدار موجود در یک نقشه را با توجه به یک کلید مشخص شده برمی‌گرداند.
MAP_SET یک کپی از نقشه را با مجموعه‌ای از کلیدهای به‌روزرسانی‌شده برمی‌گرداند
MAP_REMOVE یک کپی از نقشه را با حذف یک سری کلید برمی‌گرداند.
MAP_MERGE یک سری نقشه را با هم ادغام می‌کند.
CURRENT_CONTEXT زمینه فعلی را به عنوان یک نقشه برمی‌گرداند.
MAP_KEYS آرایه‌ای از تمام کلیدهای موجود در یک نقشه را برمی‌گرداند.
MAP_VALUES آرایه‌ای از تمام مقادیر موجود در یک نقشه را برمی‌گرداند.
MAP_ENTRIES آرایه‌ای از جفت‌های کلید-مقدار از یک نقشه را برمی‌گرداند.

نقشه

نحو:

map(key: STRING, value: ANY, ...) -> MAP

شرح:

یک نقشه از مجموعه‌ای از جفت‌های کلید-مقدار می‌سازد.

دریافت نقشه

نحو:

map_get(map: ANY, key: STRING) -> ANY

شرح:

مقدار موجود در یک نقشه را با توجه به یک کلید مشخص شده برمی‌گرداند. اگر key در نقشه وجود نداشته باشد، یا اگر آرگومان map یک MAP نباشد، مقدار ABSENT را برمی‌گرداند.

نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    field("awards").mapGet("pulitzer").as("hasPulitzerAward")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("awards").mapGet("pulitzer").as("hasPulitzerAward")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("awards").mapGet("pulitzer").as("hasPulitzerAward")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("awards").mapGet("pulitzer").alias("hasPulitzerAward")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("awards").mapGet("pulitzer").alias("hasPulitzerAward")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("awards").map_get("pulitzer").as_("hasPulitzerAward"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(mapGet(field("awards"), "pulitzer").as("hasPulitzerAward"))
        .execute()
        .get();

مجموعه نقشه

نحو:

map_set(map: MAP, key: STRING, value: ANY, ...) -> MAP

شرح:

یک کپی از مقدار map را به همراه محتویات آن که توسط یک سری جفت‌های کلید-مقدار به‌روزرسانی شده‌اند، برمی‌گرداند.

اگر نتیجه‌ی حاصل، مقداری ناموجود باشد، کلید مرتبط از نقشه حذف می‌شود.

اگر آرگومان map یک MAP نباشد، مقداری را برمی‌گرداند که وجود ندارد.

حذف نقشه

نحو:

map_remove(map: MAP, key: STRING...) -> MAP

شرح:

یک کپی از مقدار map را با حذف یک سری از کلیدها برمی‌گرداند.

ادغام نقشه

نحو:

map_merge(maps: MAP...) -> MAP

محتویات ۲ یا چند نقشه را ادغام می‌کند. اگر چندین نقشه مقادیر متناقضی داشته باشند، آخرین مقدار استفاده می‌شود.

زمینه_فعلی

نحو:

current_context() -> MAP

یک نقشه شامل تمام فیلدهای موجود در نقطه فعلی اجرا را برمی‌گرداند.

کلیدهای نقشه

نحو:

map_keys(map: MAP) -> ARRAY<STRING>

شرح:

آرایه‌ای شامل تمام کلیدهای مقدار map را برمی‌گرداند.

مقادیر نقشه

نحو:

map_values(map: MAP) -> ARRAY<ANY>

شرح:

آرایه‌ای شامل تمام مقادیر مقدار map را برمی‌گرداند.

ورودی‌های نقشه

نحو:

map_entries(map: MAP) -> ARRAY<MAP>

شرح:

آرایه‌ای شامل تمام جفت‌های کلید-مقدار در مقدار map را برمی‌گرداند.

هر جفت کلید-مقدار به شکل یک نگاشت با دو ورودی k و v خواهد بود.

مثال‌ها:

map map_entries(map)
{} []
{"غذا" : 2L} [{"k": "foo", "v" : 2L}]
{"foo" : "bar", "bar" : "foo"} [{"k": "foo"، "v" : "bar" }، {"k": "bar"، "v": "foo"}]

توابع رشته‌ای

نام توضیحات
BYTE_LENGTH تعداد BYTES در یک مقدار STRING یا BYTES را برمی‌گرداند.
CHAR_LENGTH تعداد کاراکترهای یونیکد در یک مقدار STRING را برمی‌گرداند
STARTS_WITH اگر یک STRING با پیشوند داده شده شروع شود، TRUE را برمی‌گرداند.
ENDS_WITH اگر یک STRING با پسوند مشخص شده پایان یابد TRUE را برمی‌گرداند.
LIKE اگر یک STRING با الگو مطابقت داشته باشد، TRUE را برمی‌گرداند.
REGEX_CONTAINS اگر مقداری با یک عبارت منظم مطابقت جزئی یا کامل داشته باشد، TRUE را برمی‌گرداند.
REGEX_MATCH اگر هر بخشی از یک مقدار با یک عبارت منظم مطابقت داشته باشد، TRUE برمی‌گرداند.
STRING_CONCAT چندین STRING به هم متصل کرده و یک STRING ایجاد می‌کند.
STRING_CONTAINS اگر مقدار شامل یک STRING باشد، TRUE برمی‌گرداند.
STRING_INDEX_OF ایندکس مبتنی بر 0 اولین وقوع یک مقدار STRING یا BYTES را برمی‌گرداند.
TO_UPPER یک مقدار STRING یا BYTES را به حروف بزرگ تبدیل می‌کند.
TO_LOWER یک مقدار STRING یا BYTES را به حروف کوچک تبدیل می‌کند.
SUBSTRING یک زیررشته از یک مقدار STRING یا BYTES را برمی‌گرداند.
STRING_REVERSE مقدار STRING یا BYTES را معکوس می‌کند.
STRING_REPEAT یک مقدار STRING یا BYTES را به تعداد دفعات مشخص تکرار می‌کند.
STRING_REPLACE_ALL تمام موارد وقوع یک مقدار STRING یا BYTES را جایگزین می‌کند.
STRING_REPLACE_ONE اولین مورد وقوع یک مقدار STRING یا BYTES را جایگزین می‌کند.
TRIM کاراکترهای اول و آخر یک مقدار STRING یا BYTES را حذف می‌کند.
LTRIM کاراکترهای ابتدای یک مقدار STRING یا BYTES را حذف می‌کند.
RTRIM کاراکترهای انتهایی یک مقدار STRING یا BYTES را حذف می‌کند.
SPLIT یک مقدار STRING یا BYTES را به یک آرایه تقسیم می‌کند.

طول بایت

نحو:

byte_length[T <: STRING | BYTES](value: T) -> INT64

شرح:

تعداد BYTES در یک مقدار STRING یا BYTES را برمی‌گرداند.

مثال‌ها:

ارزش byte_length(value)
"ای بی سی" ۳
"xyzabc" ۶
ب"الفبا" ۳
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    field("title").byteLength().as("titleByteLength")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("title").byteLength().as("titleByteLength")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("title").byteLength().as("titleByteLength")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("title").byteLength().alias("titleByteLength")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("title").byteLength().alias("titleByteLength")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("title").byte_length().as_("titleByteLength"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(byteLength(field("title")).as("titleByteLength"))
        .execute()
        .get();

طول کاراکتر

نحو:

char_length(value: STRING) -> INT64

شرح:

تعداد نقاط کد یونیکد را در مقدار STRING برمی‌گرداند.

مثال‌ها:

ارزش char_length(value)
"ای بی سی" ۳
«سلام» ۵
«جهان» ۵
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    field("title").charLength().as("titleCharLength")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("title").charLength().as("titleCharLength")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("title").charLength().as("titleCharLength")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("title").charLength().alias("titleCharLength")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("title").charLength().alias("titleCharLength")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("title").char_length().as_("titleCharLength"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(charLength(field("title")).as("titleCharLength"))
        .execute()
        .get();

شروع_با

نحو:

starts_with(value: STRING, prefix: STRING) -> BOOLEAN

شرح:

اگر value با prefix شروع شود، TRUE برمی‌گرداند.

مثال‌ها:

ارزش پیشوند starts_with(value, prefix)
"ای بی سی" «الف» درست
"ای بی سی" «ب» نادرست
"ای بی سی" «» درست
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    field("title").startsWith("The")
      .as("needsSpecialAlphabeticalSort")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("title").startsWith("The")
      .as("needsSpecialAlphabeticalSort")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("title").startsWith("The")
      .as("needsSpecialAlphabeticalSort")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("title").startsWith("The")
            .alias("needsSpecialAlphabeticalSort")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("title").startsWith("The")
            .alias("needsSpecialAlphabeticalSort")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("title").starts_with("The").as_("needsSpecialAlphabeticalSort")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(startsWith(field("title"), "The").as("needsSpecialAlphabeticalSort"))
        .execute()
        .get();

پایان_با

نحو:

ends_with(value: STRING, postfix: STRING) -> BOOLEAN

شرح:

اگر value با postfix خاتمه یابد، TRUE را برمی‌گرداند.

مثال‌ها:

ارزش پسوند ends_with(value, postfix)
"ای بی سی" «سی» درست
"ای بی سی" «ب» نادرست
"ای بی سی" «» درست
نود جی اس
const result = await db.pipeline()
  .collection("inventory/devices/laptops")
  .select(
    field("name").endsWith("16 inch")
      .as("16InLaptops")
  )
  .execute();
سویفت
let result = try await db.pipeline()
  .collection("inventory/devices/laptops")
  .select([
    Field("name").endsWith("16 inch")
      .as("16InLaptops")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("inventory/devices/laptops")
    .select(
        field("name").endsWith("16 inch")
            .alias("16InLaptops")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("inventory/devices/laptops")
    .select(
        field("name").endsWith("16 inch")
            .alias("16InLaptops")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("inventory/devices/laptops")
    .select(Field.of("name").ends_with("16 inch").as_("16InLaptops"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("inventory/devices/laptops")
        .select(endsWith(field("name"), "16 inch").as("16InLaptops"))
        .execute()
        .get();

لایک

نحو:

like(value: STRING, pattern: STRING) -> BOOLEAN

شرح:

اگر value با pattern مطابقت داشته باشد، TRUE را برمی‌گرداند.

مثال‌ها:

ارزش الگو like(value, pattern)
«آتش‌نشانی» "آتش٪" درست
«آتش‌نشانی» "%فروشگاه" درست
«انبار داده» "داده_ذخیره" درست
«۱۰۰٪» "۱۰۰٪" درست
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    field("genre").like("%Fiction")
      .as("anyFiction")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("genre").like("%Fiction")
      .as("anyFiction")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("genre").like("%Fiction")
      .as("anyFiction")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("genre").like("%Fiction")
            .alias("anyFiction")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("genre").like("%Fiction")
            .alias("anyFiction")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("genre").like("%Fiction").as_("anyFiction"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(like(field("genre"), "%Fiction").as("anyFiction"))
        .execute()
        .get();

مقادیر منظم (REGEX_CONTAINS)

نحو:

regex_contains(value: STRING, pattern: STRING) -> BOOLEAN

شرح:

اگر بخشی از value pattern مطابقت داشته باشد، TRUE برمی‌گرداند. اگر pattern یک عبارت منظم معتبر نباشد، این تابع error برمی‌گرداند.

عبارات منظم از سینتکس کتابخانه re2 پیروی می‌کنند.

مثال‌ها:

ارزش الگو regex_contains(value, pattern)
«آتش‌نشانی» «آتش» درست
«آتش‌نشانی» "فروشگاه $" درست
«آتش‌نشانی» «داده‌ها» نادرست
نود جی اس
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("title").regexContains("Firestore (Enterprise|Standard)")
      .as("isFirestoreRelated")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("title").regexContains("Firestore (Enterprise|Standard)")
      .as("isFirestoreRelated")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("title").regexContains("Firestore (Enterprise|Standard)")
      .as("isFirestoreRelated")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("documents")
    .select(
        field("title").regexContains("Firestore (Enterprise|Standard)")
            .alias("isFirestoreRelated")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("title").regexContains("Firestore (Enterprise|Standard)")
            .alias("isFirestoreRelated")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(
        Field.of("title")
        .regex_contains("Firestore (Enterprise|Standard)")
        .as_("isFirestoreRelated")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(
            regexContains(field("title"), "Firestore (Enterprise|Standard)")
                .as("isFirestoreRelated"))
        .execute()
        .get();

تطبیق_عبارت_عبارت_مرتب

نحو:

regex_match(value: STRING, pattern: STRING) -> BOOLEAN

شرح:

اگر value کاملاً با pattern مطابقت داشته باشد، TRUE برمی‌گرداند. اگر pattern یک عبارت منظم معتبر نباشد، این تابع error برمی‌گرداند.

عبارات منظم از سینتکس کتابخانه re2 پیروی می‌کنند.

مثال‌ها:

ارزش الگو regex_match(value, pattern)
«آتش‌نشانی» «فروشگاه اف.» درست
«آتش‌نشانی» «آتش» نادرست
«آتش‌نشانی» "^F.*e$" درست
نود جی اس
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("title").regexMatch("Firestore (Enterprise|Standard)")
      .as("isFirestoreExactly")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("title").regexMatch("Firestore (Enterprise|Standard)")
      .as("isFirestoreExactly")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("title").regexMatch("Firestore (Enterprise|Standard)")
      .as("isFirestoreExactly")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("documents")
    .select(
        field("title").regexMatch("Firestore (Enterprise|Standard)")
            .alias("isFirestoreExactly")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("title").regexMatch("Firestore (Enterprise|Standard)")
            .alias("isFirestoreExactly")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(
        Field.of("title")
        .regex_match("Firestore (Enterprise|Standard)")
        .as_("isFirestoreExactly")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(
            regexMatch(field("title"), "Firestore (Enterprise|Standard)")
                .as("isFirestoreExactly"))
        .execute()
        .get();

رشته_متصل

نحو:

string_concat(values: STRING...) -> STRING

شرح:

دو یا چند مقدار STRING را به یک نتیجه واحد پیوند می‌دهد.

مثال‌ها:

استدلال‌ها string_concat(values...)
() خطا
("a") «الف»
("abc", "def") "الف ب دف"
("a", "", "c") "آ سی"
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    field("title").stringConcat(" by ", field("author"))
      .as("fullyQualifiedTitle")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("title").stringConcat(" by ", field("author"))
      .as("fullyQualifiedTitle")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("title").concat([" by ", Field("author")])
      .as("fullyQualifiedTitle")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("title").concat(" by ", field("author"))
            .alias("fullyQualifiedTitle")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("title").concat(" by ", field("author"))
            .alias("fullyQualifiedTitle")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("title")
        .concat(" by ", Field.of("author"))
        .as_("fullyQualifiedTitle")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(stringConcat(field("title"), " by ", field("author")).as("fullyQualifiedTitle"))
        .execute()
        .get();

محتویات رشته

نحو:

string_contains(value: STRING, substring: STRING) -> BOOLEAN

شرح:

بررسی می‌کند که آیا value شامل substring String به صورت تحت‌اللفظی است یا خیر.

مثال‌ها:

ارزش زیررشته string_contains(value, substring)
"ای بی سی" «ب» درست
"ای بی سی" «دی» نادرست
"ای بی سی" «» درست
"آ سی" «.» درست
«☃☃☃» «☃» درست
نود جی اس
const result = await db.pipeline()
  .collection("articles")
  .select(
    field("body").stringContains("Firestore")
      .as("isFirestoreRelated")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("articles")
  .select(
    field("body").stringContains("Firestore")
      .as("isFirestoreRelated")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("articles")
  .select([
    Field("body").stringContains("Firestore")
      .as("isFirestoreRelated")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("articles")
    .select(
        field("body").stringContains("Firestore")
            .alias("isFirestoreRelated")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("articles")
    .select(
        field("body").stringContains("Firestore")
            .alias("isFirestoreRelated")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("articles")
    .select(Field.of("body").string_contains("Firestore").as_("isFirestoreRelated"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("articles")
        .select(stringContains(field("body"), "Firestore").as("isFirestoreRelated"))
        .execute()
        .get();

STRING_INDEX_OF

نحو:

string_index_of[T <: STRING | BYTES](value: T, search: T) -> INT64

شرح:

ایندکس مبتنی بر ۰ اولین رخداد search در value را برمی‌گرداند.

  • اگر search پیدا نشود، -1 را برمی‌گرداند.
  • اگر value یک مقدار STRING باشد، نتیجه بر حسب امتیاز کد یونیکد اندازه‌گیری می‌شود. اگر مقدار یک مقدار BYTES باشد، بر حسب بایت اندازه‌گیری می‌شود.
  • اگر search یک مقدار STRING یا BYTES خالی باشد، نتیجه 0 است.

مثال‌ها:

ارزش جستجو string_index_of(value, search)
"سلام دنیا" «ای» ۴
"سلام دنیا" «ل» ۲
"سلام دنیا" «ز» -1
«موز» «نا» ۲
"ای بی سی" «» 0
ب"الفبا" ب "ب" ۱
"ه" "ه" 0
ب "é" ب "é" 0

به بالا

نحو:

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

شرح:

یک مقدار STRING یا BYTES را به حروف بزرگ تبدیل می‌کند.

اگر یک بایت یا کاراکتر با یک کاراکتر الفبایی کوچک UTF-8 مطابقت نداشته باشد، بدون تغییر منتقل می‌شود.

مثال‌ها:

ارزش to_upper(value)
"ای بی سی" «ای‌بی‌سی»
«ای‌بی‌سی» «ای‌بی‌سی»
ب"الفبا" ب "ای بی سی"
ب"آ۱سی" ب "A1C"
نود جی اس
const result = await db.pipeline()
  .collection("authors")
  .select(
    field("name").toUpper()
      .as("uppercaseName")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("authors")
  .select(
    field("name").toUpper()
      .as("uppercaseName")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("authors")
  .select([
    Field("name").toUpper()
      .as("uppercaseName")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("authors")
    .select(
        field("name").toUpper()
            .alias("uppercaseName")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("authors")
    .select(
        field("name").toUpper()
            .alias("uppercaseName")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("authors")
    .select(Field.of("name").to_upper().as_("uppercaseName"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("authors")
        .select(toUpper(field("name")).as("uppercaseName"))
        .execute()
        .get();

به پایین

نحو:

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

شرح:

یک مقدار STRING یا BYTES را به حروف کوچک تبدیل می‌کند.

اگر یک بایت یا کاراکتر با یک کاراکتر الفبایی بزرگ UTF-8 مطابقت نداشته باشد، بدون تغییر منتقل می‌شود.

مثال‌ها:

ارزش to_lower(value)
«ای‌بی‌سی» "ای بی سی"
«ای‌بی‌سی» "ای بی سی"
«ای وان سی» «ای۱سی»
ب "ای بی سی" ب"الفبا"
نود جی اس
const result = await db.pipeline()
  .collection("authors")
  .select(
    field("genre").toLower().equal("fantasy")
      .as("isFantasy")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("authors")
  .select(
    field("genre").toLower().equal("fantasy")
      .as("isFantasy")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("authors")
  .select([
    Field("genre").toLower().equal("fantasy")
      .as("isFantasy")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("authors")
    .select(
        field("genre").toLower().equal("fantasy")
            .alias("isFantasy")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("authors")
    .select(
        field("genre").toLower().equal("fantasy")
            .alias("isFantasy")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("authors")
    .select(Field.of("genre").to_lower().equal("fantasy").as_("isFantasy"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("authors")
        .select(equal(toLower(field("genre")), "fantasy").as("isFantasy"))
        .execute()
        .get();

زیررشته

نحو:

substring[T <: STRING | BYTES](input: T, position: INT64) -> T
substring[T <: STRING | BYTES](input: T, position: INT64, length: INT64) -> T

شرح:

یک زیررشته از input را با شروع از position (اندیس مبتنی بر صفر) و شامل ورودی‌هایی با حداکثر length ، برمی‌گرداند. اگر length ارائه نشود، زیررشته را از position تا انتهای input برمی‌گرداند.

  • اگر input یک مقدار STRING باشد، position و length بر حسب نقاط کد یونیکد اندازه‌گیری می‌شوند. اگر مقدار BYTES باشد، بر حسب بایت اندازه‌گیری می‌شوند.

  • اگر position بزرگتر از طول input باشد، یک زیررشته خالی برگردانده می‌شود. اگر position بعلاوه length بزرگتر از طول input باشد، زیررشته تا انتهای input کوتاه می‌شود.

  • اگر position منفی باشد، موقعیت از انتهای ورودی گرفته می‌شود. اگر position منفی بزرگتر از اندازه ورودی باشد، موقعیت روی صفر تنظیم می‌شود. length باید غیر منفی باشد.

مثال‌ها:

وقتی length ارائه نشده باشد:

ورودی موقعیت substring(input, position)
"ای بی سی" 0 "ای بی سی"
"ای بی سی" ۱ "بی سی"
"ای بی سی" ۳ «»
"ای بی سی" -1 «سی»
ب"الفبا" ۱ بی"بی سی"

وقتی length ارائه می‌شود:

ورودی موقعیت طول substring(input, position, length)
"ای بی سی" 0 ۱ «الف»
"ای بی سی" ۱ ۲ "بی سی"
"ای بی سی" -1 ۱ «سی»
ب"الفبا" 0 ۱ ب "الف"
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .where(field("title").startsWith("The "))
  .select(
    field("title").substring(4)
      .as("titleWithoutLeadingThe")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .where(field("title").startsWith("The "))
  .select(
    field("title").substring(4)
      .as("titleWithoutLeadingThe")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .where(Field("title").startsWith("The "))
  .select([
    Field("title").substring(position: 4)
      .as("titleWithoutLeadingThe")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .where(field("title").startsWith("The "))
    .select(
        field("title")
          .substring(constant(4),
            field("title").charLength().subtract(4))
            .alias("titleWithoutLeadingThe")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .where(field("title").startsWith("The "))
    .select(
        field("title").substring(
          constant(4),
            field("title").charLength().subtract(4))
            .alias("titleWithoutLeadingThe")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .where(Field.of("title").starts_with("The "))
    .select(Field.of("title").substring(4).as_("titleWithoutLeadingThe"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .where(startsWith(field("title"), "The "))
        .select(
            substring(field("title"), constant(4), field("title").charLength())
                .as("titleWithoutLeadingThe"))
        .execute()
        .get();

معکوس رشته

نحو:

string_reverse[T <: STRING | BYTES](input: T) -> T

شرح:

ورودی ارائه شده را به ترتیب معکوس برمی‌گرداند.

وقتی ورودی یک STRING باشد، کاراکترها توسط نقاط کد یونیکد و وقتی ورودی یک مقدار BYTES باشد، توسط بایت‌ها مشخص می‌شوند.

مثال‌ها:

ورودی string_reverse(input)
"ای بی سی" "سی بی ای"
"الف🌹ب" "بی🌹ا"
«سلام» "الله"
ب"الفبا" ب"سی بی ای"
نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    field("name").reverse().as("reversedName")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("name").reverse().as("reversedName")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("name").reverse().as("reversedName")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("name").reverse().alias("reversedName")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("name").reverse().alias("reversedName")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("name").string_reverse().as_("reversedName"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(reverse(field("name")).as("reversedName"))
        .execute()
        .get();

تکرار رشته

نحو:

string_repeat[T <: STRING | BYTES](input: T, repetitions: INT64) -> T

شرح:

تعداد repetitions input را برمی‌گرداند.

  • repetitions باید یک عدد صحیح غیر منفی باشند.
  • اگر repetitions 0 باشد، یک مقدار خالی از همان نوع input را برمی‌گرداند.
  • اگر نتیجه از حداکثر اندازه مجاز (۱ مگابایت) بیشتر شود، خطایی برگردانده می‌شود.

مثال‌ها:

ورودی تکرارها string_repeat(input, repetitions)
"فو" ۳ "فوفوفو"
"فو" 0 «»
«الف» ۳ «آآ»
ب"آب" ۲ ب"باب"
"ه🦆" ۲ "این🦆این🦆"

STRING_REPLACE_ALL

نحو:

string_replace_all[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T

شرح:

تمام رخدادهای غیر همپوشانی find در input را با replacement جایگزین می‌کند.

  • تطابق‌ها به حروف کوچک و بزرگ حساس هستند.
  • اگر find خالی باشد، هیچ جایگزینی انجام نمی‌شود.

مثال‌ها:

ورودی پیدا کردن جایگزینی string_replace_all(input, find, replacement)
"فوبارفو" "فو" «باز» «بازبارباز»
«باباب» «آبا» «سی» "کباب"
"فوبار" «ای» «» "فبار"
"ه🦆🌎🦆" «🦆» «الف» "اِا🌎ا"
ب"الفبا" ب "ب" ب"د" ب"adc"

یک رشته را جایگزین کنید

نحو:

string_replace_one[T <: STRING | BYTES](input: T, find: T, replacement: T) -> T

شرح:

اولین مورد از find در input را با replacement جایگزین می‌کند.

  • تطابق‌ها به حروف کوچک و بزرگ حساس هستند.
  • اگر find خالی باشد، هیچ جایگزینی انجام نمی‌شود.

مثال‌ها:

ورودی پیدا کردن جایگزینی string_replace_one(input, find, replacement)
"فوبارفو" "فو" «باز» "بازبرفو"
"ه" "ه" «الف» «الف»
ب"فوبار" ب "او" ب"ز" ب"فزوبار"

تریم

نحو:

trim[T <: STRING | BYTES](input: T, values_to_trim: T) -> T
trim[T <: STRING | BYTES](input: T) -> T

شرح:

مجموعه‌ای مشخص از BYTES یا CHARS را از ابتدا و انتهای input ارائه شده برش می‌دهد.

  • اگر هیچ values_to_trim ارائه نشده باشد، کاراکترهای فاصله را حذف می‌کند.

مثال‌ها:

وقتی values_to_trim ارائه نشده باشد:

ورودی trim(input)
"فو" "فو"
ب" غذا " ب "غذا"
"فو" "فو"
«» «»
« » «»
"\t غذا \n" "فو"
ب"\t غذا \n" ب "غذا"
"\r\f\v غذا \r\f\v" "فو"
\r\f\v غذا ب "غذا"

وقتی values_to_trim ارائه می‌شود:

ورودی مقادیر_به_تریم trim(input, values_to_trim)
"abcbfooaacb" "ای بی سی" "فو"
"abcdaabadbac" "ای بی سی" «داآباد»
ب"C1C2C3" ب"سی۱" ب"سی۲سی۳"
ب"C1C2" "فو" خطا
"فو" ب"سی۱" خطا

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("name").trim().as("whitespaceTrimmedName")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("name").trim(" \n\t").as("whitespaceTrimmedName")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("name").trim().alias("whitespaceTrimmedName")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("name").trim().alias("whitespaceTrimmedName")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("name").trim().as_("whitespaceTrimmedName"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(trim(field("name")).as("whitespaceTrimmedName"))
        .execute()
        .get();

لتریم

نحو:

ltrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
ltrim[T <: STRING | BYTES](value: T) -> T

شرح:

مجموعه مشخصی از BYTES یا CHARS را از ابتدای value ارائه شده برش می‌دهد.

  • اگر to_trim ارائه نشده باشد، کاراکترهای فاصله‌ی ابتدای تابع را حذف می‌کند.

مثال‌ها:

چه زمانی to_trim ارائه نمی‌شود:

ارزش ltrim(value)
"فو" "فو"
"فو" "فو"

چه زمانی to_trim ارائه می‌شود:

ارزش to_trim ltrim(value, to_trim)
"آاِی بی سی" «الف» "بی سی"
«آباکابا» "با" "کابا"
"ه" "ه" «»

آرتریم

نحو:

rtrim[T <: STRING | BYTES](value: T, to_trim: T) -> T
rtrim[T <: STRING | BYTES](value: T) -> T

شرح:

مجموعه مشخصی از BYTES یا CHARS را از انتهای value ارائه شده برش می‌دهد.

  • اگر to_trim ارائه نشده باشد، کاراکترهای فاصله‌ی انتهایی را حذف می‌کند.

مثال‌ها:

چه زمانی to_trim ارائه نمی‌شود:

ارزش rtrim(value)
"فو" "فو"
"فو" "فو"

چه زمانی to_trim ارائه می‌شود:

ارزش to_trim rtrim(value, to_trim)
"ای بی سی سی" «سی» "آب"
«آباکابا» "با" "آباک"
"ه" "ه" «»

تقسیم

نحو:

split(input: STRING) -> ARRAY<STRING>
split[T <: STRING | BYTES](input: T, delimiter: T) -> ARRAY<T>

شرح:

یک مقدار STRING یا BYTES را با استفاده از یک جداکننده تقسیم می‌کند.

  • برای STRING جداکننده پیش‌فرض کاما است , جداکننده به عنوان یک رشته واحد در نظر گرفته می‌شود.

  • برای BYTES ، باید یک جداکننده مشخص کنید.

  • تقسیم بر روی یک جداکننده خالی، آرایه‌ای از نقاط کد یونیکد برای مقادیر STRING و آرایه‌ای از BYTES برای مقادیر BYTES تولید می‌کند.

  • تقسیم یک STRING خالی، یک ARRAY با یک STRING خالی برمی‌گرداند.

مثال‌ها:

وقتی delimiter ارائه نشده باشد:

ورودی split(input)
«غذا، بار، غذا» ["غذا"، "بار"، "غذا"]
"فو" ["غذا"]
"،غذا،" ["", "غذا", ""]
«» [""]
ب"C120C2C4" خطا

وقتی delimiter ارائه می‌شود:

ورودی جداکننده split(input, delimiter)
"فو بار فو" « » ["غذا"، "بار"، "غذا"]
"فو بار فو" «ز» ["غذای بار غذا"]
"ای بی سی" «» ["الف"، "ب"، "ج"]
ب"C1، C2، C4" ب"" [ب"C1"، ب"C2"، ب"C4"]
ب "ای بی سی" ب"" [ب"الف"، ب"ب"، ب"پ"]
"فو" ب"سی۱" خطا

توابع مهر زمانی

نام توضیحات
CURRENT_TIMESTAMP یک TIMESTAMP مربوط به زمان درخواست تولید می‌کند.
TIMESTAMP_TRUNC یک TIMESTAMP به یک جزئیات مشخص کوتاه می‌کند.
UNIX_MICROS_TO_TIMESTAMP تعداد میکروثانیه‌ها از 1970-01-01 00:00:00 UTC را به TIMESTAMP تبدیل می‌کند.
UNIX_MILLIS_TO_TIMESTAMP تعداد میلی‌ثانیه‌ها از 1970-01-01 00:00:00 UTC را به TIMESTAMP تبدیل می‌کند.
UNIX_SECONDS_TO_TIMESTAMP تعداد ثانیه‌ها از 1970-01-01 00:00:00 UTC را به TIMESTAMP تبدیل می‌کند.
TIMESTAMP_ADD یک بازه زمانی به TIMESTAMP اضافه می‌کند.
TIMESTAMP_SUB یک بازه زمانی را از TIMESTAMP کم می‌کند.
TIMESTAMP_TO_UNIX_MICROS تابع TIMESTAMP تعداد میکروثانیه‌های سپری شده از 1970-01-01 00:00:00 UTC را به آن تبدیل می‌کند.
TIMESTAMP_TO_UNIX_MILLIS تابع TIMESTAMP تعداد میلی ثانیه های سپری شده از 1970-01-01 00:00:00 UTC را به آن تبدیل می کند.
TIMESTAMP_TO_UNIX_SECONDS یک TIMESTAMP را به تعداد ثانیه‌ها از 1970-01-01 00:00:00 UTC تبدیل می‌کند.
TIMESTAMP_DIFF تعداد کل فواصل unit مشخص شده بین دو TIMESTAMP را برمی‌گرداند.
TIMESTAMP_EXTRACT یک part خاص (مثلاً سال، ماه، روز) را از یک TIMESTAMP استخراج می‌کند.

مهر زمان فعلی

نحو:

current_timestamp() -> TIMESTAMP

شرح:

مهر زمانی را در ابتدای input زمان درخواست دریافت می‌کند (که به صورت تعداد میکروثانیه‌ها از 1970-01-01 00:00:00 UTC تفسیر می‌شود).

این در یک پرس و جو پایدار است و اگر چندین بار فراخوانی شود، همیشه به همان مقدار برمی‌گردد.

مهر زمانی_TRUNC

نحو:

timestamp_trunc(timestamp: TIMESTAMP, granularity: STRING[, timezone: STRING]) -> TIMESTAMP

شرح:

یک مهر زمانی را تا جزئیات مشخص شده کوتاه می‌کند.

آرگومان granularity باید یک رشته و یکی از موارد زیر باشد:

  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day
  • week
  • week([weekday])
  • month
  • quarter
  • year
  • isoyear

اگر آرگومان timezone ارائه شود، کوتاه‌سازی بر اساس مرزهای تقویم منطقه زمانی داده شده انجام خواهد شد (مثلاً کوتاه‌سازی روز در منطقه زمانی داده شده تا نیمه‌شب کوتاه می‌شود). این کوتاه‌سازی با توجه به زمان تابستانی انجام می‌شود.

اگر timezone ارائه نشود، کوتاه‌سازی بر اساس مرزهای تقویم UTC انجام خواهد شد.

آرگومان timezone باید یک نمایش رشته‌ای از یک منطقه زمانی از پایگاه داده tz باشد، برای مثال America/New_York . همچنین می‌توان با مشخص کردن یک انحراف از GMT ، از یک انحراف زمانی سفارشی استفاده کرد.

مثال‌ها:

timestamp granularity timezone timestamp_trunc(timestamp, granularity, timezone)
‎۲۰۰۰-۰۱-۰۱ ۱۰:۲۰:۳۰:۱۲۳۴۵۶ UTC «دوم» ارائه نشده است ۲۰۰۱-۰۱-۰۱ ۱۰:۲۰:۳۰ UTC
‎۱۹۹۷-۰۵-۳۱ ۰۴:۳۰:۳۰ UTC‎ «روز» ارائه نشده است ‎۱۹۹۷-۰۵-۳۱ ۰۰:۰۰:۰۰ UTC‎
‎۱۹۹۷-۰۵-۳۱ ۰۴:۳۰:۳۰ UTC‎ «روز» «آمریکا/لس‌آنجلس» ‎۱۹۹۷-۰۵-۳۰ ۰۷:۰۰:۰۰ UTC‎
‏‎2001-03-16‎‏ ساعت ‏04:00:00 UTC‎‏ "هفته (جمعه) ارائه نشده است ‏‎2001-03-16‎‏ ساعت ‏۰۰:۰۰:۰۰ UTC‎‏
‏۲۳ مارس ۲۰۰۱‏ ساعت ‏۰۴:۰۰:۰۰ به وقت جهانی "هفته (جمعه) «آمریکا/لس‌آنجلس» ‏۲۳ مارس ۲۰۰۱‏ ۱۷:۰۰:۰۰ به وقت جهانی
‎۲۴-۰۱-۲۰۲۶ ساعت ۲۰:۰۰:۰۰ به وقت جهانی‎ «ماه» «به وقت گرینویچ+۰۶:۳۲:۴۳» ‎2026-01-01T06:32:43 UTC

UNIX_MICROS_TO_TIMESTAMP

نحو:

unix_micros_to_timestamp(input: INT64) -> TIMESTAMP

شرح:

input (که به صورت تعداد میکروثانیه‌ها از 1970-01-01 00:00:00 UTC تفسیر می‌شود) را به یک TIMESTAMP تبدیل می‌کند. اگر input نتواند به یک TIMESTAMP معتبر تبدیل شود، error می‌دهد.

مثال‌ها:

input unix_micros_to_timestamp(input)
0 لیتر ۱۹۷۰-۰۱-۰۱ ۰۰:۰۰:۰۰ UTC
۴۰۰۱۲۳۴۵۶L ۱۹۷۰-۰۱-۰۱ ۰۰:۰۶:۴۰.۱۲۳۴۵۶ UTC
-1000000 لیتر ‏۱۹۶۹-۱۲-۳۱ ۲۳:۵۹:۵۹ UTC‏
نود جی اس
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("createdAtMicros").unixMicrosToTimestamp().as("createdAtString")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("createdAtMicros").unixMicrosToTimestamp().as("createdAtString")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("createdAtMicros").unixMicrosToTimestamp().as("createdAtString")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("documents")
    .select(
        field("createdAtMicros").unixMicrosToTimestamp().alias("createdAtString")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("createdAtMicros").unixMicrosToTimestamp().alias("createdAtString")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(
        Field.of("createdAtMicros")
        .unix_micros_to_timestamp()
        .as_("createdAtString")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(unixMicrosToTimestamp(field("createdAtMicros")).as("createdAtString"))
        .execute()
        .get();

UNIX_MILLIS_TO_TIMESTAMP

نحو:

unix_millis_to_timestamp(input: INT64) -> TIMESTAMP

شرح:

input (که به صورت تعداد میلی‌ثانیه‌ها از 1970-01-01 00:00:00 UTC تفسیر می‌شود) را به یک TIMESTAMP تبدیل می‌کند. اگر input نتواند به یک TIMESTAMP معتبر تبدیل شود، error می‌دهد.

مثال‌ها:

input unix_millis_to_timestamp(input)
0 لیتر ۱۹۷۰-۰۱-۰۱ ۰۰:۰۰:۰۰ UTC
۴۰۰۰۱۲۳ لیتر ۱۹۷۰-۰۱-۰۱ ۰۱:۰۶:۴۰.۱۲۳ UTC
-1000000 لیتر ‏۱۹۶۹-۱۲-۳۱ ۲۳:۴۳:۲۰ UTC‏
نود جی اس
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("createdAtMillis").unixMillisToTimestamp().as("createdAtString")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("createdAtMillis").unixMillisToTimestamp().as("createdAtString")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("createdAtMillis").unixMillisToTimestamp().as("createdAtString")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("documents")
    .select(
        field("createdAtMillis").unixMillisToTimestamp().alias("createdAtString")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("createdAtMillis").unixMillisToTimestamp().alias("createdAtString")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(
        Field.of("createdAtMillis")
        .unix_millis_to_timestamp()
        .as_("createdAtString")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(unixMillisToTimestamp(field("createdAtMillis")).as("createdAtString"))
        .execute()
        .get();

UNIX_SECONDS_TO_TIMESTAMP

نحو:

unix_seconds_to_timestamp(input: INT64) -> TIMESTAMP

شرح:

input (که به صورت تعداد ثانیه‌ها از 1970-01-01 00:00:00 UTC تفسیر می‌شود) را به یک TIMESTAMP تبدیل می‌کند. اگر input نتواند به یک TIMESTAMP معتبر تبدیل شود، error می‌دهد.

مثال‌ها:

input unix_seconds_to_timestamp(input)
0 لیتر ۱۹۷۰-۰۱-۰۱ ۰۰:۰۰:۰۰ UTC
۶۰ لیتر ۱۹۷۰-۰۱-۰۱ ۰۰:۰۱:۰۰ UTC
-300 لیتر ‎۱۹۶۹-۱۲-۳۱ ۲۳:۵۵:۰۰ UTC‎
نود جی اس
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("createdAtSeconds").unixSecondsToTimestamp().as("createdAtString")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("createdAtSeconds").unixSecondsToTimestamp().as("createdAtString")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("createdAtSeconds").unixSecondsToTimestamp().as("createdAtString")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("documents")
    .select(
        field("createdAtSeconds").unixSecondsToTimestamp().alias("createdAtString")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("createdAtSeconds").unixSecondsToTimestamp().alias("createdAtString")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(
        Field.of("createdAtSeconds")
        .unix_seconds_to_timestamp()
        .as_("createdAtString")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(unixSecondsToTimestamp(field("createdAtSeconds")).as("createdAtString"))
        .execute()
        .get();

افزودن مهر زمان

نحو:

timestamp_add(timestamp: TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP

شرح:

amount از unit timestamp را اضافه می‌کند. آرگومان amount می‌تواند منفی باشد، در این صورت معادل TIMESTAMP_SUB خواهد بود.

آرگومان unit باید یک رشته و یکی از موارد زیر باشد:

  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day

اگر برچسب زمانی حاصل در محدوده TIMESTAMP قرار نگیرد، خطا می‌دهد.

مثال‌ها:

timestamp unit amount timestamp_add(timestamp, unit, amount)
۲۰۲۵-۰۲-۲۰ ساعت ۰۰:۰۰:۰۰ به وقت جهانی "دقیقه" ۲ لیتر ۲۰۲۵-۰۲-۲۰ ساعت ۰۰:۰۲:۰۰ به وقت جهانی
۲۰۲۵-۰۲-۲۰ ساعت ۰۰:۰۰:۰۰ به وقت جهانی «ساعت» -4 لیتر ۲۰۲۵-۰۲-۱۹ ساعت ۲۰:۰۰:۰۰ به وقت جهانی
۲۰۲۵-۰۲-۲۰ ساعت ۰۰:۰۰:۰۰ به وقت جهانی «روز» ۵ لیتر ‏۲۵ فوریه ۲۰۲۵، ساعت ۰۰:۰۰:۰۰ به وقت هماهنگ جهانی
نود جی اس
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("createdAt").timestampAdd("day", 3653).as("expiresAt")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("createdAt").timestampAdd("day", 3653).as("expiresAt")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("createdAt").timestampAdd(3653, .day).as("expiresAt")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("documents")
    .select(
        field("createdAt")
          .timestampAdd("day", 3653)
          .alias("expiresAt")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("createdAt").timestampAdd("day", 3653).alias("expiresAt")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(Field.of("createdAt").timestamp_add("day", 3653).as_("expiresAt"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(timestampAdd(field("createdAt"), "day", 3653).as("expiresAt"))
        .execute()
        .get();

زیرعنوان مهر زمانی

نحو:

timestamp_sub(timestamp: TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP

شرح:

amount بر حسب unit را از timestamp کم می‌کند. آرگومان amount می‌تواند منفی باشد، در این صورت معادل TIMESTAMP_ADD خواهد بود.

آرگومان unit باید یک رشته و یکی از موارد زیر باشد:

  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day

اگر برچسب زمانی حاصل در محدوده TIMESTAMP قرار نگیرد، خطا می‌دهد.

مثال‌ها:

timestamp unit amount timestamp_sub(timestamp, unit, amount)
‎2026-07-04 00:00:00 UTC‎ "دقیقه" ۴۰ لیتر ‎2026-07-03 23:20:00 UTC
‎2026-07-04 00:00:00 UTC‎ «ساعت» -24 لیتر ‎2026-07-05 00:00:00 UTC‎
‎2026-07-04 00:00:00 UTC‎ «روز» ۳ لیتر ‎۲۰۲۶-۰۷-۰۱ ۰۰:۰۰:۰۰ UTC‎
نود جی اس
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("expiresAt").timestampSubtract("day", 14).as("sendWarningTimestamp")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("expiresAt").timestampSubtract("day", 14).as("sendWarningTimestamp")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("expiresAt").timestampSubtract(14, .day).as("sendWarningTimestamp")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("documents")
    .select(
        field("expiresAt")
          .timestampSubtract("day", 14)
          .alias("sendWarningTimestamp")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("expiresAt").timestampSubtract("day", 14).alias("sendWarningTimestamp")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(
        Field.of("expiresAt")
        .timestamp_subtract("day", 14)
        .as_("sendWarningTimestamp")
    )
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(timestampSubtract(field("expiresAt"), "day", 14).as("sendWarningTimestamp"))
        .execute()
        .get();

مهر زمانی برای یونیکس و میکرو

نحو:

timestamp_to_unix_micros(input: TIMESTAMP) -> INT64

شرح:

input به تعداد میکروثانیه‌ها از 1970-01-01 00:00:00 UTC تبدیل می‌کند. سطوح بالاتر دقت را با گرد کردن به ابتدای میکروثانیه، کوتاه می‌کند.

مثال‌ها:

input timestamp_to_unix_micros(input)
۱۹۷۰-۰۱-۰۱ ۰۰:۰۰:۰۰ UTC 0 لیتر
۱۹۷۰-۰۱-۰۱ ۰۰:۰۶:۴۰.۱۲۳۴۵۶ UTC ۴۰۰۱۲۳۴۵۶L
‏۱۹۶۹-۱۲-۳۱ ۲۳:۵۹:۵۹ UTC‏ -1000000 لیتر
نود جی اس
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixMicros().as("unixMicros")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixMicros().as("unixMicros")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("dateString").timestampToUnixMicros().as("unixMicros")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("documents")
    .select(
        field("dateString").timestampToUnixMicros().alias("unixMicros")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("dateString").timestampToUnixMicros().alias("unixMicros")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(Field.of("dateString").timestamp_to_unix_micros().as_("unixMicros"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(timestampToUnixMicros(field("dateString")).as("unixMicros"))
        .execute()
        .get();

مهر زمانی به یونیکس میلی

نحو:

timestamp_to_unix_millis(input: TIMESTAMP) -> INT64

شرح:

input به تعداد میلی‌ثانیه‌ها از 1970-01-01 00:00:00 UTC تبدیل می‌کند. سطوح بالاتر دقت را با گرد کردن به ابتدای میلی‌ثانیه، کوتاه می‌کند.

مثال‌ها:

input timestamp_to_unix_millis(input)
۱۹۷۰-۰۱-۰۱ ۰۰:۰۰:۰۰ UTC 0 لیتر
۱۹۷۰-۰۱-۰۱ ۰۱:۰۶:۴۰.۱۲۳ UTC ۴۰۰۰۱۲۳ لیتر
۱۹۶۹-۱۲-۳۱ ۲۳:۴۳:۲۰ -1000000 لیتر
نود جی اس
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixMillis().as("unixMillis")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixMillis().as("unixMillis")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("dateString").timestampToUnixMillis().as("unixMillis")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("documents")
    .select(
        field("dateString").timestampToUnixMillis().alias("unixMillis")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("dateString").timestampToUnixMillis().alias("unixMillis")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(Field.of("dateString").timestamp_to_unix_millis().as_("unixMillis"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(timestampToUnixMillis(field("dateString")).as("unixMillis"))
        .execute()
        .get();

مهر زمان به ثانیه در یونیکس

نحو:

timestamp_to_unix_seconds(input: TIMESTAMP) -> INT64

شرح:

input به تعداد ثانیه‌ها از 1970-01-01 00:00:00 UTC تبدیل می‌کند. سطوح بالاتر دقت را با گرد کردن به ابتدای ثانیه به پایین، کوتاه می‌کند.

مثال‌ها:

input timestamp_to_unix_seconds(input)
۱۹۷۰-۰۱-۰۱ ۰۰:۰۰:۰۰ UTC 0 لیتر
۱۹۷۰-۰۱-۰۱ ۰۰:۰۱:۰۰ UTC ۶۰ لیتر
‎۱۹۶۹-۱۲-۳۱ ۲۳:۵۵:۰۰ UTC‎ -300 لیتر
نود جی اس
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixSeconds().as("unixSeconds")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixSeconds().as("unixSeconds")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("documents")
  .select([
    Field("dateString").timestampToUnixSeconds().as("unixSeconds")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("documents")
    .select(
        field("dateString").timestampToUnixSeconds().alias("unixSeconds")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("documents")
    .select(
        field("dateString").timestampToUnixSeconds().alias("unixSeconds")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("documents")
    .select(Field.of("dateString").timestamp_to_unix_seconds().as_("unixSeconds"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(timestampToUnixSeconds(field("dateString")).as("unixSeconds"))
        .execute()
        .get();

تفاوت زمانی

نحو:

timestamp_diff(end: TIMESTAMP, start: TIMESTAMP, unit: STRING) -> INT64

شرح:

تعداد کل فواصل unit مشخص شده بین دو TIMESTAMP را برمی‌گرداند.

  • اگر end قبل از start باشد، مقدار منفی را برمی‌گرداند.
  • هر واحد کسری را کوتاه می‌کند. برای مثال، timestamp_diff("2021-01-01 00:00:01", "2021-01-01 00:00:00", "minute") 0 را برمی‌گرداند.

آرگومان unit باید یک رشته و یکی از موارد زیر باشد:

  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day

مثال‌ها:

end start unit timestamp_diff(end, start, unit)
‎2026-07-04 00:01:00 UTC‎ ‎2026-07-04 00:00:00 UTC‎ «دوم» ۶۰ لیتر
‎2026-07-04 00:00:00 UTC‎ ‎2026-07-05 00:00:00 UTC‎ «روز» -1 لیتر
‎2026-07-04 00:00:59 UTC ‎2026-07-04 00:00:00 UTC‎ "دقیقه" 0 لیتر

استخراج مهر زمان

نحو:

timestamp_extract(timestamp: TIMESTAMP, part: STRING[, timezone: STRING]) -> INT64

شرح:

یک part خاص (مثلاً سال، ماه، روز) را از timestamp استخراج می‌کند.

آرگومان part باید یک رشته و یکی از موارد زیر باشد:

  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day
  • dayofweek : مقداری بین ۱ (یکشنبه) و ۷ (شنبه) را برمی‌گرداند.
  • dayofyear
  • week : شماره هفته سال را برمی‌گرداند، که از ۱ برای اولین یکشنبه سال شروع می‌شود.
  • week([weekday]) شماره هفته از سال را برمی‌گرداند، که از weekday مشخص شده شروع می‌شود.
  • month
  • quarter
  • year
  • isoweek : شماره هفته ISO 8601 را برمی‌گرداند.
  • isoyear : سال شماره‌گذاری هفته ISO 8601 را برمی‌گرداند.

اگر آرگومان timezone ارائه شود، استخراج بر اساس تقویم منطقه زمانی داده شده انجام خواهد شد. استخراج بر اساس زمان تابستانی انجام می‌شود.

اگر timezone ارائه نشود، استخراج بر اساس UTC انجام خواهد شد.

آرگومان timezone باید یک نمایش رشته‌ای از یک منطقه زمانی از پایگاه داده منطقه زمانی باشد، برای مثال America/New_York . همچنین می‌توان با مشخص کردن یک انحراف از GMT ، از یک انحراف زمانی سفارشی استفاده کرد.

مثال‌ها:

timestamp part timezone timestamp_extract(timestamp, part, timezone)
۲۰۲۵-۰۲-۲۰ ساعت ۱۰:۲۰:۳۰ به وقت جهانی «سال» ارائه نشده است ۲۰۲۵
۲۰۲۵-۰۲-۲۰ ساعت ۱۰:۲۰:۳۰ به وقت جهانی «روز» ارائه نشده است ۲۰
‎۲۰۲۵-۱۲-۳۱ ۲۳:۵۹:۵۹ UTC «سال» «آسیا/توکیو» ۲۰۲۶

توابع نوع

نام توضیحات
TYPE نوع مقدار را به صورت STRING برمی‌گرداند.
IS_TYPE اگر مقدار با نوع مشخص شده مطابقت داشته باشد، true را برمی‌گرداند.

نوع

نحو:

type(input: ANY) -> STRING

شرح:

یک رشته از نوع input را برمی‌گرداند.

اگر مقداری داده نشود، NULL را برمی‌گرداند.

مثال‌ها:

input type(input)
تهی "تهی"
درست "بولی"
۱ "int32"
-3 لیتر "int64"
۳.۱۴ "شناور64"
‎2024-01-01T00:00:00Z UTC "برچسب زمانی"
"فو" "رشته"
ب "غذا" "بایت"
[1، 2] "آرایه"
{"الف": 1} "نقشه"
path("c/d") «مرجع»
vector([1.0, 2.0]) "بردار"
غایب تهی

نمونه‌های مشتری

نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(field("title").notEqual("1984").as("not1984"))
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("title").notEqual("1984").as("not1984"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("title").notEqual("1984").as("not1984")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("title").notEqual("1984").alias("not1984"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("title").notEqual("1984").alias("not1984"))
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("title").not_equal("1984").as_("not1984"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(notEqual(field("title"), "1984").as("not1984"))
        .execute()
        .get();

نوع IS

نحو:

is_type(input: ANY, type: STRING) -> BOOLEAN

شرح:

اگر input با type مشخص شده مطابقت داشته باشد، مقدار true و در غیر این صورت false را برمی‌گرداند. اگر input داده نشود، NULL را برمی‌گرداند.

رشته‌های type پشتیبانی‌شده عبارتند از:

  • "null"
  • "boolean"
  • "int32"
  • "int64"
  • "float64"
  • "decimal128"
  • "number"
  • "timestamp"
  • "string"
  • "bytes"
  • "array"
  • "map"
  • "reference"
  • "vector"
  • "geo_point"
  • "max_key"
  • "min_key"
  • "object_id"
  • "regex"
  • "bson_timestamp"

مثال‌ها:

input type is_type(input, type)
تهی "تهی" درست
درست "بولی" درست
۳.۱۴ "شناور64" درست
"فو" "رشته" درست
ب "غذا" "رشته" نادرست
[1، 2] "آرایه" درست
{"الف": 1} "نقشه" درست
vector([1.0, 2.0]) "بردار" درست
غایب "رشته" تهی
"بار" «دیگر» خطا

توابع برداری

نام توضیحات
COSINE_DISTANCE فاصله کسینوسی بین دو بردار را برمی‌گرداند
DOT_PRODUCT حاصلضرب نقطه‌ای بین دو بردار را برمی‌گرداند
EUCLIDEAN_DISTANCE فاصله اقلیدسی بین دو بردار را برمی‌گرداند
MANHATTAN_DISTANCE فاصله منهتن بین دو بردار را برمی‌گرداند
VECTOR_LENGTH تعداد عناصر یک بردار را برمی‌گرداند

کسینوس_فاصله

نحو:

cosine_distance(x: VECTOR, y: VECTOR) -> FLOAT64

شرح:

فاصله کسینوسی بین x و y را برمی‌گرداند.

نود جی اس
const sampleVector = [0.0, 1, 2, 3, 4, 5];
const result = await db.pipeline()
  .collection("books")
  .select(
    field("embedding").cosineDistance(sampleVector).as("cosineDistance")
  )
  .execute();

Web

const sampleVector = [0.0, 1, 2, 3, 4, 5];
const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("embedding").cosineDistance(sampleVector).as("cosineDistance")));
سویفت
let sampleVector = [0.0, 1, 2, 3, 4, 5]
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("embedding").cosineDistance(sampleVector).as("cosineDistance")
  ])
  .execute()

Kotlin

val sampleVector = doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0)
val result = db.pipeline()
    .collection("books")
    .select(
        field("embedding").cosineDistance(sampleVector).alias("cosineDistance")
    )
    .execute()

Java

double[] sampleVector = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("embedding").cosineDistance(sampleVector).alias("cosineDistance")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field
from google.cloud.firestore_v1.vector import Vector

sample_vector = Vector([0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("embedding").cosine_distance(sample_vector).as_("cosineDistance")
    )
    .execute()
)
جاوا
double[] sampleVector = new double[] {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(cosineDistance(field("embedding"), sampleVector).as("cosineDistance"))
        .execute()
        .get();

محصول_نقطه‌ای

نحو:

dot_product(x: VECTOR, y: VECTOR) -> FLOAT64

شرح:

حاصلضرب نقطه‌ای x و y را برمی‌گرداند.

نود جی اس
const sampleVector = [0.0, 1, 2, 3, 4, 5];
const result = await db.pipeline()
  .collection("books")
  .select(
    field("embedding").dotProduct(sampleVector).as("dotProduct")
  )
  .execute();

Web

const sampleVector = [0.0, 1, 2, 3, 4, 5];
const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("embedding").dotProduct(sampleVector).as("dotProduct")
  )
);
سویفت
let sampleVector = [0.0, 1, 2, 3, 4, 5]
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("embedding").dotProduct(sampleVector).as("dotProduct")
  ])
  .execute()

Kotlin

val sampleVector = doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0)
val result = db.pipeline()
    .collection("books")
    .select(
        field("embedding").dotProduct(sampleVector).alias("dotProduct")
    )
    .execute()

Java

double[] sampleVector = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("embedding").dotProduct(sampleVector).alias("dotProduct")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field
from google.cloud.firestore_v1.vector import Vector

sample_vector = Vector([0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("embedding").dot_product(sample_vector).as_("dotProduct"))
    .execute()
)
جاوا
double[] sampleVector = new double[] {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(dotProduct(field("embedding"), sampleVector).as("dotProduct"))
        .execute()
        .get();

فاصله اقلیدسی

نحو:

euclidean_distance(x: VECTOR, y: VECTOR) -> FLOAT64

شرح:

فاصله اقلیدسی بین x و y را محاسبه می‌کند.

نود جی اس
const sampleVector = [0.0, 1, 2, 3, 4, 5];
const result = await db.pipeline()
  .collection("books")
  .select(
    field("embedding").euclideanDistance(sampleVector).as("euclideanDistance")
  )
  .execute();

Web

const sampleVector = [0.0, 1, 2, 3, 4, 5];
const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("embedding").euclideanDistance(sampleVector).as("euclideanDistance")
  )
);
سویفت
let sampleVector = [0.0, 1, 2, 3, 4, 5]
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("embedding").euclideanDistance(sampleVector).as("euclideanDistance")
  ])
  .execute()

Kotlin

val sampleVector = doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0)
val result = db.pipeline()
    .collection("books")
    .select(
        field("embedding").euclideanDistance(sampleVector).alias("euclideanDistance")
    )
    .execute()

Java

double[] sampleVector = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("embedding").euclideanDistance(sampleVector).alias("euclideanDistance")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field
from google.cloud.firestore_v1.vector import Vector

sample_vector = Vector([0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("embedding")
        .euclidean_distance(sample_vector)
        .as_("euclideanDistance")
    )
    .execute()
)
جاوا
double[] sampleVector = new double[] {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(euclideanDistance(field("embedding"), sampleVector).as("euclideanDistance"))
        .execute()
        .get();

فاصله منهتن

نحو:

manhattan_distance(x: VECTOR, y: VECTOR) -> FLOAT64

شرح:

فاصله منهتن بین x و y را محاسبه می‌کند.

طول بردار

نحو:

vector_length(vector: VECTOR) -> INT64

شرح:

تعداد عناصر موجود در یک VECTOR را برمی‌گرداند.

نود جی اس
const result = await db.pipeline()
  .collection("books")
  .select(
    field("embedding").vectorLength().as("vectorLength")
  )
  .execute();

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("embedding").vectorLength().as("vectorLength")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("embedding").vectorLength().as("vectorLength")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(
        field("embedding").vectorLength().alias("vectorLength")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        field("embedding").vectorLength().alias("vectorLength")
    )
    .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("embedding").vector_length().as_("vectorLength"))
    .execute()
)
جاوا
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(vectorLength(field("embedding")).as("vectorLength"))
        .execute()
        .get();