DocumentSnapshot
包含從 Firestore 資料庫中的文件讀取的資料。可以使用.data()
或.get(<field>)
提取資料以取得特定欄位。
對於指向不存在文件的DocumentSnapshot
,任何資料存取都會傳回「未定義」。您可以使用exists()
方法明確驗證文件是否存在。
簽名:
export declare class DocumentSnapshot<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>
建構函數
建構函數 | 修飾符 | 描述 |
---|---|---|
(構造函數)() | 建構DocumentSnapshot 類別的新實例 |
特性
財產 | 修飾符 | 類型 | 描述 |
---|---|---|---|
ID | 細繩 | 提供文檔 ID 的DocumentSnapshot 屬性。 | |
元數據 | 快照元數據 | 有關DocumentSnapshot 的元數據,包括有關其來源和本地修改的資訊。 | |
參考 | 文件參考<應用程式模型類型,Db模型類型> | DocumentSnapshot 中所包含的文件的DocumentReference 。 |
方法
方法 | 修飾符 | 描述 |
---|---|---|
數據(選項) | 以Object 形式檢索文件中的所有欄位。如果文件不存在,則傳回undefined 。預設情況下,尚未設定為最終值的serverTimestamp() 值將傳回為null 。您可以透過傳遞選項物件來覆寫它。 | |
存在() | 傳回資料是否存在。如果文檔存在則為 true。 | |
獲取(字段路徑,選項) | 檢索fieldPath 指定的欄位。如果文件或欄位不存在,則傳回undefined 。預設情況下,尚未設定為最終值的serverTimestamp() 將傳回null 。您可以透過傳遞選項物件來覆寫它。 |
文件快照。(建構函數)
建構DocumentSnapshot
類別的新實例
簽名:
protected constructor();
文件快照.id
提供文檔 ID 的DocumentSnapshot
屬性。
簽名:
get id(): string;
文件快照.元數據
有關DocumentSnapshot
的元數據,包括有關其來源和本地修改的資訊。
簽名:
readonly metadata: SnapshotMetadata;
文檔快照.ref
DocumentSnapshot
中所包含的文件的DocumentReference
。
簽名:
get ref(): DocumentReference<AppModelType, DbModelType>;
文檔快照.data()
以Object
檢索文件中的所有字段。如果文件不存在,則傳回undefined
。
預設情況下,尚未設定為最終值的serverTimestamp()
值將傳回null
。您可以透過傳遞選項物件來覆寫它。
簽名:
data(options?: SnapshotOptions): AppModelType | undefined;
參數
範圍 | 類型 | 描述 |
---|---|---|
選項 | 快照選項 | 選項對象,用於配置如何從快照檢索資料(例如,尚未設定為其最終值的伺服器時間戳記的所需行為)。 |
返回:
應用程式模型類型 |不明確的
包含文件中所有欄位的Object
,如果文件不存在則undefined
。
DocumentSnapshot.exists()
傳回資料是否存在。如果文檔存在則為 true。
簽名:
exists(): this is QueryDocumentSnapshot<AppModelType, DbModelType>;
返回:
這是QueryDocumentSnapshot <應用程式模型類型,Db模型類型>
文檔快照.get()
檢索fieldPath
指定的字段。如果文件或欄位不存在,則傳回undefined
。
預設情況下,尚未設定為最終值的serverTimestamp()
將傳回null
。您可以透過傳遞選項物件來覆寫它。
簽名:
get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
參數
範圍 | 類型 | 描述 |
---|---|---|
字段路徑 | 字串|字段路徑 | 特定欄位的路徑(例如“foo”或“foo.bar”)。 |
選項 | 快照選項 | 選項對象,用於配置如何從快照中檢索欄位(例如,尚未設定為其最終值的伺服器時間戳記的所需行為)。 |
返回:
任何
指定字段位置處的資料;如果文件中不存在此類字段,則資料未定義。