توابع مقایسه

توابع مقایسه

نام شرح
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 را برمی‌گرداند.

Node.js
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"))
);
Swift
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();
رفتن
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.Equal(firestore.FieldOf("rating"), 5).As("hasPerfectRating"),
	)).
	Execute(ctx)

بزرگ‌تر از

نحو:

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

شرح:

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

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

نمونه:

x y greater_than(x, y)
یک لیتر ۰٫۰ TRUE
یک لیتر یک لیتر FALSE
یک لیتر 2L FALSE
«foo» ‫۰ لیتر FALSE
‫۰ لیتر «foo» FALSE
غیرعددی ‫۰ لیتر FALSE
‫۰ لیتر غیرعددی FALSE
NULL NULL FALSE
Node.js
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"))
);
Swift
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();
رفتن
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.GreaterThan(firestore.FieldOf("rating"), 4).As("hasHighRating"),
	)).
	Execute(ctx)

GREATER_THAN_OR_EQUAL

نحو:

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
یک لیتر 2L FALSE
«foo» ‫۰ لیتر FALSE
‫۰ لیتر «foo» FALSE
غیرعددی ‫۰ لیتر FALSE
‫۰ لیتر غیرعددی FALSE
NULL NULL TRUE
Node.js
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"))
);
Swift
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();
رفتن
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.GreaterThanOrEqual(firestore.FieldOf("published"), 1900).As("publishedIn20thCentury"),
	)).
	Execute(ctx)

کمتر از

نحو:

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

شرح:

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

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

نمونه:

x y less_than(x, y)
یک لیتر ۰٫۰ FALSE
یک لیتر یک لیتر FALSE
یک لیتر 2L TRUE
«foo» ‫۰ لیتر FALSE
‫۰ لیتر «foo» FALSE
غیرعددی ‫۰ لیتر FALSE
‫۰ لیتر غیرعددی FALSE
NULL NULL FALSE
Node.js
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"))
);
Swift
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();
رفتن
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.LessThan(firestore.FieldOf("published"), 1923).As("isPublicDomainProbably"),
	)).
	Execute(ctx)

LESS_THAN_OR_EQUAL

نحو:

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

شرح:

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

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

نمونه:

x y less_than(x, y)
یک لیتر ۰٫۰ FALSE
یک لیتر یک لیتر TRUE
یک لیتر 2L TRUE
«foo» ‫۰ لیتر FALSE
‫۰ لیتر «foo» FALSE
غیرعددی ‫۰ لیتر FALSE
‫۰ لیتر غیرعددی FALSE
NULL NULL TRUE
Node.js
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"))
);
Swift
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();
رفتن
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.LessThanOrEqual(firestore.FieldOf("rating"), 2).As("hasBadRating"),
	)).
	Execute(ctx)

NOT_EQUAL

نحو:

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

شرح:

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

نمونه:

x y not_equal(x, y)
یک لیتر یک لیتر FALSE
۱٫۰ یک لیتر FALSE
‫۱٫۰- یک لیتر TRUE
غیرعددی ‫۰ لیتر TRUE
غیرعددی غیرعددی FALSE
NULL NULL FALSE
NULL ABSENT TRUE
Node.js
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"))
);
Swift
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();
رفتن
snapshot := client.Pipeline().
	Collection("books").
	Select(firestore.Fields(
		firestore.NotEqual(firestore.FieldOf("title"), "1984").As("not1984"),
	)).
	Execute(ctx)

CMP

نحو:

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

شرح:

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

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

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

نمونه:

x y cmp(x, y)
یک لیتر یک لیتر ‫۰ لیتر
۱٫۰ یک لیتر ‫۰ لیتر
‫۱٫۰- یک لیتر ‫-۱ لیتر
‫۴۲٫۵ روز «foo» ‫-۱ لیتر
NULL NULL ‫۰ لیتر
NULL ABSENT ‫۰ لیتر