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