دوال المقارنة

دوال المقارنة

الاسم الوصف
EQUAL مقارنة المساواة
GREATER_THAN مقارنة "أكبر من"
GREATER_THAN_OR_EQUAL مقارنة أكبر من أو يساوي
LESS_THAN مقارنة "أقل من"
LESS_THAN_OR_EQUAL مقارنة أقل من أو يساوي
NOT_EQUAL مقارنة "لا يساوي"
CMP مقارنة عامة

EQUAL

البنية:

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

أمثلة:

x y equal(x, y)
1 لتر 1 لتر TRUE
1.0 1 لتر TRUE
-1.0 1 لتر FALSE
NaN NaN TRUE
NULL NULL TRUE
NULL ABSENT FALSE

الوصف:

تعرض هذه الدالة TRUE إذا كان x وy متساويَين، و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();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").equal(5).as_("hasPerfectRating"))
    .execute()
)
Java
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

البنية:

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

الوصف:

تعرض هذه الدالة TRUE إذا كانت قيمة x أكبر من y، وتعرض FALSE في الحالات الأخرى.

إذا لم تكن السمتان x وy قابلتَين للمقارنة، يتم عرض FALSE.

أمثلة:

x y greater_than(x, y)
1 لتر 0.0 TRUE
1 لتر 1 لتر FALSE
1 لتر ‫2 لتر FALSE
"foo" 0 لتر FALSE
0 لتر "foo" FALSE
NaN 0 لتر FALSE
0 لتر NaN 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();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").greater_than(4).as_("hasHighRating"))
    .execute()
)
Java
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

الوصف:

تعرض هذه الدالة TRUE إذا كانت قيمة x أكبر من أو تساوي y، وتعرض FALSE في الحالات الأخرى.

إذا لم تكن السمتان x وy قابلتَين للمقارنة، يتم عرض FALSE.

أمثلة:

x y greater_than_or_equal(x, y)
1 لتر 0.0 TRUE
1 لتر 1 لتر TRUE
1 لتر ‫2 لتر FALSE
"foo" 0 لتر FALSE
0 لتر "foo" FALSE
NaN 0 لتر FALSE
0 لتر NaN 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();
Python
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()
)
Java
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

البنية:

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

الوصف:

تعرض هذه الدالة TRUE إذا كانت قيمة x أقل من y، وFALSE في الحالات الأخرى.

إذا لم تكن السمتان x وy قابلتَين للمقارنة، يتم عرض FALSE.

أمثلة:

x y less_than(x, y)
1 لتر 0.0 FALSE
1 لتر 1 لتر FALSE
1 لتر ‫2 لتر TRUE
"foo" 0 لتر FALSE
0 لتر "foo" FALSE
NaN 0 لتر FALSE
0 لتر NaN 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();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("published").less_than(1923).as_("isPublicDomainProbably"))
    .execute()
)
Java
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

الوصف:

تعرض هذه الدالة TRUE إذا كانت قيمة x أقل من أو تساوي y، وتعرض FALSE في الحالات الأخرى.

إذا لم تكن السمتان x وy قابلتَين للمقارنة، يتم عرض FALSE.

أمثلة:

x y less_than(x, y)
1 لتر 0.0 FALSE
1 لتر 1 لتر TRUE
1 لتر ‫2 لتر TRUE
"foo" 0 لتر FALSE
0 لتر "foo" FALSE
NaN 0 لتر FALSE
0 لتر NaN 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();
Python
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()
)
Java
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

الوصف:

تعرض هذه الدالة TRUE إذا كانت قيمة x لا تساوي y، وتعرض FALSE في الحالات الأخرى.

أمثلة:

x y not_equal(x, y)
1 لتر 1 لتر FALSE
1.0 1 لتر FALSE
-1.0 1 لتر TRUE
NaN 0 لتر TRUE
NaN NaN 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();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("title").not_equal("1984").as_("not1984"))
    .execute()
)
Java
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)
1 لتر 1 لتر 0 لتر
1.0 1 لتر 0 لتر
-1.0 1 لتر -1L
42.5D "foo" -1L
NULL NULL 0 لتر
NULL ABSENT 0 لتر