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”)。

返回:

任何

指定字段位置处的数据;如果文档中不存在此类字段,则数据未定义。