類型函式

型別函式

名稱 說明
TYPE STRING 形式傳回值的型別。
IS_TYPE 如果值符合指定型別,則傳回 true

類型

語法:

type(input: ANY) -> STRING

說明:

傳回 input 型別的字串表示法。

如果提供的值不存在,則傳回 NULL

範例:

input type(input)
空值 「null」
true 「boolean」
1 「int32」
-3L "int64"
3.14 「float64」
2024-01-01T00:00:00Z UTC 「timestamp」
"foo" 「string」
b"foo" 「bytes」
[1, 2] 「array」
{"a": 1} 「map」
path("c/d") 「reference」
vector([1.0, 2.0]) 「vector」
ABSENT 空值

用戶端範例

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();

IS_TYPE

語法:

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)
空值 「null」 true
true 「boolean」 true
3.14 「float64」 true
"foo" 「string」 true
b"foo" 「string」 false
[1, 2] 「array」 true
{"a": 1} 「map」 true
vector([1.0, 2.0]) 「vector」 true
ABSENT 「string」 空值
「bar」 「other」 錯誤