DocumentReference class

DocumentReference是指 Firestore 数据库中的文档位置,可用于写入、读取或侦听该位置。引用位置处的文档可能存在,也可能不存在。

签名:

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

特性

财产修饰符类型描述
转换器Firestore数据转换器<AppModelType,DbModelType> |无效的如果提供,则为与此实例关联的FirestoreDataConverter
火库火库文档所在的Firestore实例。例如,这对于执行事务很有用。
ID细绳文档在其集合中的标识符。
家长收藏参考<应用程序模型类型,Db模型类型>DocumentReference所属的集合。
小路细绳表示引用文档的路径(相对于数据库的根目录)的字符串。
类型(未声明)此 Firestore 引用的类型。

方法

方法修饰符描述
与转换器(转换器)对此DocumentReference应用自定义数据转换器,允许您将自己的自定义模型对象与 Firestore 结合使用。当您调用setDoc(),获取文档()等,使用返回的DocumentReference实例,提供的转换器将在NewDbModelType类型的 Firestore 数据和您的自定义类型NewAppModelType之间进行转换。
与转换器(转换器)移除电流转换器。

文档参考转换器

如果提供,则为与此实例关联的FirestoreDataConverter

签名:

readonly converter: FirestoreDataConverter<AppModelType, DbModelType> | null;

文档Reference.firestore

文档所在的Firestore实例。例如,这对于执行事务很有用。

签名:

readonly firestore: Firestore;

文档参考.id

文档在其集合中的标识符。

签名:

get id(): string;

文档参考.parent

DocumentReference所属的集合。

签名:

get parent(): CollectionReference<AppModelType, DbModelType>;

文档参考.path

表示引用文档的路径(相对于数据库的根目录)的字符串。

签名:

get path(): string;

文档参考.type

此 Firestore 引用的类型。

签名:

readonly type = "document";

DocumentReference.withConverter()

将自定义数据转换器应用于此DocumentReference ,允许您将自己的自定义模型对象与 Firestore 结合使用。当您调用setDoc(),获取文档()等,使用返回的DocumentReference实例,提供的转换器将在NewDbModelType类型的 Firestore 数据和您的自定义类型NewAppModelType之间进行转换

签名:

withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): DocumentReference<NewAppModelType, NewDbModelType>;

参数

范围类型描述
转换器Firestore数据转换器<新应用程序模型类型、新数据库模型类型>将对象与 Firestore 相互转换。

返回:

文档参考<新应用程序模型类型、新数据库模型类型>

使用提供的转换器的DocumentReference

DocumentReference.withConverter()

移除电流转换器。

签名:

withConverter(converter: null): DocumentReference<DocumentData, DocumentData>;

参数

范围类型描述
转换器无效的null删除当前转换器。

返回:

文档参考<文档数据,文档数据>

不使用转换器的DocumentReference<DocumentData, DocumentData>