比較函式參考資料

比較函式

名稱 說明
EQUAL 相等比較
GREATER_THAN 大於比較
GREATER_THAN_OR_EQUAL 大於或等於比較
LESS_THAN 小於比較結果
LESS_THAN_OR_EQUAL 小於或等於比較
NOT_EQUAL 不等於比較

EQUAL

語法:

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

範例:

x y equal(x, y)
1L 1L TRUE
1.0 1L TRUE
-1.0 1L FALSE
NaN NaN TRUE
NULL NULL TRUE
NULL ABSENT FALSE

說明:

如果 xy 相等,則傳回 TRUE,否則傳回 FALSE

Node.js
const result = await db.pipeline()
  .collection("books")
  .select(field("rating").equal(5).as("hasPerfe  .execute();test.firestore.js

網頁

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").equal(5).as(&qung"))
);test.firestore.js
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").equal(5).as("hasPerfexecute()PipelineSnippets.swift
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(field("rating").equal(5).alias("hasPerfec)
    .execute()DocSnippets.kt
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").equal(5).alias("hasPerfect   .execute();DocSnippets.java
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").equal(5).as_("hasPerfectRcute()
)firestore_pipelines.py
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(equal(field("rating"), 5).as("hasPerfectRating"))
      .get();PipelineSnippets.java

GREATER_THAN

語法:

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

說明:

如果 x 大於 y,則傳回 TRUE,否則傳回 FALSE

如果 xy 無法比較,則傳回 FALSE

範例:

x y greater_than(x, y)
1L 0.0 TRUE
1L 1L FALSE
1L 2L FALSE
"foo" 0L FALSE
0L "foo" FALSE
NaN 0L FALSE
0L NaN FALSE
NULL NULL FALSE
Node.js
const result = await db.pipeline()
  .collection("books")
  .select(field("rating").greaterThan(4).as("hasHi  .execute();test.firestore.js

網頁

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").greaterThan(4).as(ng"))
);test.firestore.js
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").greaterThan(4).as("hasHixecute()PipelineSnippets.swift
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(field("rating").greaterThan(4).alias("hasHig)
    .execute()DocSnippets.kt
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").greaterThan(4).alias("hasHigh   .execute();DocSnippets.java
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").greater_than(4).as_("hasHighRcute()
)firestore_pipelines.py
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(greaterThan(field("rating"), 4).as("hasHighRating"))
      .get();PipelineSnippets.java

GREATER_THAN_OR_EQUAL

語法:

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

說明:

如果 x 大於或等於 y,則傳回 TRUE,否則傳回 FALSE

如果 xy 無法比較,則傳回 FALSE

範例:

x y greater_than_or_equal(x, y)
1L 0.0 TRUE
1L 1L TRUE
1L 2L FALSE
"foo" 0L FALSE
0L "foo" FALSE
NaN 0L FALSE
0L NaN FALSE
NULL NULL TRUE
Node.js
const result = await db.pipeline()
  .collection("books")
  .select(field("published").greaterThanOrEqual(1900).as("publishedIn20t  .execute();test.firestore.js

網頁

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("published").greaterThanOrEqual(1900).as("pubry"))
);test.firestore.js
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([Field("published").greaterThanOrEqual(1900).as("publishedIn20txecute()PipelineSnippets.swift
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(field("published").greaterThanOrEqual(1900).alias("publishedIn20th)
    .execute()DocSnippets.kt
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("published").greaterThanOrEqual(1900).alias("publishedIn20thC   .execute();DocSnippets.java
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_("publishedIn20thCenturycute()
)firestore_pipelines.py
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(greaterThanOrEqual(field("published"), 1900).as("publishedIn20thCentury"))
      .get();PipelineSnippets.java

LESS_THAN

語法:

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

說明:

如果 x 小於 y,則會傳回 TRUE,否則會傳回 FALSE

如果 xy 無法比較,則傳回 FALSE

範例:

x y less_than(x, y)
1L 0.0 FALSE
1L 1L FALSE
1L 2L TRUE
"foo" 0L FALSE
0L "foo" FALSE
NaN 0L FALSE
0L NaN FALSE
NULL NULL FALSE
Node.js
const result = await db.pipeline()
  .collection("books")
  .select(field("published").lessThan(1923).as("isPublicDomain  .execute();test.firestore.js

網頁

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("published").lessThan(1923).as("isPly"))
);test.firestore.js
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([Field("published").lessThan(1923).as("isPublicDomainxecute()PipelineSnippets.swift
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(field("published").lessThan(1923).alias("isPublicDomainP)
    .execute()DocSnippets.kt
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("published").lessThan(1923).alias("isPublicDomainPr   .execute();DocSnippets.java
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("published").less_than(1923).as_("isPublicDomainProcute()
)firestore_pipelines.py
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(lessThan(field("published"), 1923).as("isPublicDomainProbably"))
      .get();PipelineSnippets.java

LESS_THAN_OR_EQUAL

語法:

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

說明:

如果 x 小於或等於 y,則傳回 TRUE,否則傳回 FALSE

如果 xy 無法比較,則傳回 FALSE

範例:

x y less_than(x, y)
1L 0.0 FALSE
1L 1L TRUE
1L 2L TRUE
"foo" 0L FALSE
0L "foo" FALSE
NaN 0L FALSE
0L NaN FALSE
NULL NULL TRUE
Node.js
const result = await db.pipeline()
  .collection("books")
  .select(field("rating").lessThanOrEqual(2).as("hasB  .execute();test.firestore.js

網頁

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").lessThanOrEqual(2).asng"))
);test.firestore.js
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").lessThanOrEqual(2).as("hasBxecute()PipelineSnippets.swift
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(field("rating").lessThanOrEqual(2).alias("hasBa)
    .execute()DocSnippets.kt
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").lessThanOrEqual(2).alias("hasBad   .execute();DocSnippets.java
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_("hasBadRcute()
)firestore_pipelines.py
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(lessThanOrEqual(field("rating"), 2).as("hasBadRating"))
      .get();PipelineSnippets.java

NOT_EQUAL

語法:

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

說明:

如果 x 不等於 y,則傳回 TRUE,否則傳回 FALSE

範例:

x y not_equal(x, y)
1L 1L FALSE
1.0 1L FALSE
-1.0 1L TRUE
NaN 0L TRUE
NaN NaN FALSE
NULL NULL FALSE
NULL ABSENT TRUE
Node.js
const result = await db.pipeline()
  .collection("books")
  .select(field("title").notEqual("1984"4"))
  .execute();test.firestore.js

網頁

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("title").notEqual("quot;not1984"))
);test.firestore.js
Swift
let result = try await db.pipeline()
  .collection("books")
  .select([Field("title").notEqual("1984"t;)])
  .execute()PipelineSnippets.swift
Kotlin
Android
val result = db.pipeline()
    .collection("books")
    .select(field("title").notEqual("1984").al984"))
    .execute()DocSnippets.kt
Java
Android
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("title").notEqual("1984").ali"))
    .execute();DocSnippets.java
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("title").not_equal("1984").as)
    .execute()
)firestore_pipelines.py
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("books")
        .select(notEqual(field("title"), "1984").as("not1984&que()
        .get();PipelineSnippets.java

後續步驟