DocumentSnapshot class

DocumentSnapshot包含從 Firestore 資料庫中的文件讀取的資料。可以使用.data().get(<field>)提取資料以取得特定欄位。

對於指向不存在文件的DocumentSnapshot ,任何資料存取都會傳回「未定義」。您可以使用exists()方法明確驗證文件是否存在。

簽名:

export declare class DocumentSnapshot<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> 

建構函數

建構函數修飾符描述
(構造函數)()建構DocumentSnapshot類別的新實例

特性

財產修飾符類型描述
ID細繩提供文檔 ID 的DocumentSnapshot屬性。
參考文件參考<應用程式模型類型,Db模型類型> DocumentSnapshot中所包含的文件的DocumentReference

方法

方法修飾符描述
數據()Object形式檢索文件中的所有欄位。如果文件不存在,則傳回undefined
存在()指示快照位置處的文件是否存在。
獲取(字段路徑)檢索fieldPath指定的欄位。如果文件或欄位不存在,則傳回undefined

文件快照。(建構函數)

建構DocumentSnapshot類別的新實例

簽名:

protected constructor();

文件快照.id

提供文檔 ID 的DocumentSnapshot屬性。

簽名:

get id(): string;

文檔快照.ref

DocumentSnapshot中所包含的文件的DocumentReference

簽名:

get ref(): DocumentReference<AppModelType, DbModelType>;

文檔快照.data()

Object檢索文件中的所有字段。如果文件不存在,則傳回undefined

簽名:

data(): AppModelType | undefined;

返回:

應用程式模型類型 |不明確的

包含文件中所有欄位的Object ,如果文件不存在則undefined

DocumentSnapshot.exists()

指示快照位置處的文件是否存在。

簽名:

exists(): this is QueryDocumentSnapshot<AppModelType, DbModelType>;

返回:

這是QueryDocumentSnapshot <應用程式模型類型,Db模型類型>

如果文檔存在則為 true。

文檔快照.get()

檢索fieldPath指定的字段。如果文件或欄位不存在,則傳回undefined

簽名:

get(fieldPath: string | FieldPath): any;

參數

範圍類型描述
字段路徑字串|字段路徑特定欄位的路徑(例如“foo”或“foo.bar”)。

返回:

任何

指定字段位置處的資料;如果文件中不存在此類字段,則資料未定義。