Hàm kiểu
| Tên | Mô tả |
TYPE
|
Trả về kiểu của giá trị dưới dạng STRING.
|
IS_TYPE
|
Trả về true nếu giá trị khớp với kiểu đã chỉ định.
|
LOẠI
Cú pháp:
type(input: ANY) -> STRING
Nội dung mô tả:
Trả về một chuỗi đại diện cho kiểu input.
Nếu bạn cung cấp một giá trị không có, hàm sẽ trả về NULL.
Ví dụ:
input |
type(input) |
|---|---|
| NULL | "null" |
| đúng | "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" |
| KHÔNG CÓ | NULL |
Ví dụ về ứng dụng khách
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
Cú pháp:
is_type(input: ANY, type: STRING) -> BOOLEAN
Nội dung mô tả:
Trả về true nếu input khớp với type đã chỉ định, nếu không thì trả về false.
Nếu bạn cung cấp một input không có, hàm sẽ trả về NULL.
Các chuỗi type được hỗ trợ là:
"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"
Ví dụ:
input |
type |
is_type(input, type) |
|---|---|---|
| NULL | "null" | đúng |
| đúng | "boolean" | đúng |
| 3.14 | "float64" | đúng |
| "foo" | "string" | đúng |
| b"foo" | "string" | false |
| [1, 2] | "array" | đúng |
| {"a": 1} | "map" | đúng |
vector([1.0, 2.0]) |
"vector" | đúng |
| KHÔNG CÓ | "string" | NULL |
| "bar" | "other" | LỖI |