ฟังก์ชันประเภท
| ชื่อ | คำอธิบาย |
TYPE
|
แสดงผลประเภทของค่าเป็น STRING
|
IS_TYPE
|
แสดงผล true หากค่าตรงกับประเภทที่ระบุ
|
ประเภท
ไวยากรณ์:
type(input: ANY) -> STRING
คำอธิบาย:
แสดงผลการแสดงสตริงของประเภท input
หากได้รับค่าที่ไม่มีอยู่ จะแสดงผล NULL
ตัวอย่าง
input |
type(input) |
|---|---|
| NULL | "null" |
| จริง | "บูลีน" |
| 1 | "int32" |
| -3L | "int64" |
| 3.14 | "float64" |
| 2024-01-01T00:00:00Z UTC | "timestamp" |
| "foo" | "string" |
| b"foo" | "ไบต์" |
| [1, 2] | "array" |
| {"a": 1} | "map" |
path("c/d") |
"อ้างอิง" |
vector([1.0, 2.0]) |
"เวกเตอร์" |
| ABSENT | NULL |
ตัวอย่างลูกค้า
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
คำอธิบาย:
แสดงผล true หาก input ตรงกับ type ที่ระบุ หรือแสดงผล 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 | "null" | จริง |
| จริง | "บูลีน" | จริง |
| 3.14 | "float64" | จริง |
| "foo" | "string" | จริง |
| b"foo" | "string" | เท็จ |
| [1, 2] | "array" | จริง |
| {"a": 1} | "map" | จริง |
vector([1.0, 2.0]) |
"เวกเตอร์" | จริง |
| ABSENT | "string" | NULL |
| "bar" | "อื่นๆ" | ข้อผิดพลาด |