对交易的引用。
传递给事务的updateFunction
的Transaction
对象提供在事务上下文中读取和写入数据的方法。参见runTransaction() 。
签名:
export declare class Transaction
方法
方法 | 修饰符 | 描述 |
---|---|---|
删除(文档参考) | 删除所提供的DocumentReference引用的文档。 | |
获取(文档参考) | 读取所提供的DocumentReference引用的文档。 | |
设置(文档参考,数据) | 写入所提供的DocumentReference引用的文档。如果该文档尚不存在,则会创建该文档。 | |
设置(文档参考、数据、选项) | 写入所提供的DocumentReference引用的文档。如果该文档尚不存在,则会创建该文档。如果您提供merge 或mergeFields ,则提供的数据可以合并到现有文档中。 | |
更新(文档参考,数据) | 更新所提供的DocumentReference引用的文档中的字段。如果应用于不存在的文档,更新将会失败。 | |
更新(文档参考,字段,值,moreFieldsAndValues) | 更新所提供的DocumentReference引用的文档中的字段。如果应用于不存在的文档,更新将会失败。可以通过提供点分隔的字段路径字符串或提供FieldPath 对象来更新嵌套字段。 |
事务.delete()
删除所提供的DocumentReference引用的文档。
签名:
delete<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>): this;
参数
范围 | 类型 | 描述 |
---|---|---|
文档参考 | 文档参考<应用程序模型类型,Db模型类型> | 对要删除的文档的引用。 |
返回:
这
此Transaction
实例。用于链接方法调用。
交易.get()
读取所提供的DocumentReference引用的文档。
签名:
get<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>): Promise<DocumentSnapshot<AppModelType, DbModelType>>;
参数
范围 | 类型 | 描述 |
---|---|---|
文档参考 | 文档参考<应用程序模型类型,Db模型类型> | 对要阅读的文档的引用。 |
返回:
Promise<文档快照<应用程序模型类型,Db模型类型>>
包含读取数据的DocumentSnapshot
。
交易.set()
写入所提供的DocumentReference引用的文档。如果该文档尚不存在,则会创建该文档。
签名:
set<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: WithFieldValue<AppModelType>): this;
参数
范围 | 类型 | 描述 |
---|---|---|
文档参考 | 文档参考<应用程序模型类型,Db模型类型> | 对要设置的文档的引用。 |
数据 | 带字段值<应用程序模型类型> | 文档的字段和值的对象。 |
返回:
这
此Transaction
实例。用于链接方法调用。
例外情况
错误 - 如果提供的输入不是有效的 Firestore 文档。
交易.set()
写入所提供的DocumentReference引用的文档。如果该文档尚不存在,则会创建该文档。如果您提供merge
或mergeFields
,所提供的数据可以合并到现有文档中。
签名:
set<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: PartialWithFieldValue<AppModelType>, options: SetOptions): this;
参数
范围 | 类型 | 描述 |
---|---|---|
文档参考 | 文档参考<应用程序模型类型,Db模型类型> | 对要设置的文档的引用。 |
数据 | 带字段值的部分<应用程序模型类型> | 文档的字段和值的对象。 |
选项 | 设置选项 | 用于配置设置行为的对象。 |
返回:
这
此Transaction
实例。用于链接方法调用。
例外情况
错误 - 如果提供的输入不是有效的 Firestore 文档。
交易.update()
更新所提供的DocumentReference引用的文档中的字段。如果应用于不存在的文档,更新将会失败。
签名:
update<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: UpdateData<DbModelType>): this;
参数
范围 | 类型 | 描述 |
---|---|---|
文档参考 | 文档参考<应用程序模型类型,Db模型类型> | 对要更新的文档的引用。 |
数据 | 更新数据<数据库模型类型> | 包含用于更新文档的字段和值的对象。字段可以包含点来引用文档中的嵌套字段。 |
返回:
这
此Transaction
实例。用于链接方法调用。
例外情况
错误 - 如果提供的输入不是有效的 Firestore 数据。
交易.update()
更新所提供的DocumentReference引用的文档中的字段。如果应用于不存在的文档,更新将会失败。
可以通过提供点分隔的字段路径字符串或提供FieldPath
对象来更新嵌套字段。
签名:
update<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this;
参数
范围 | 类型 | 描述 |
---|---|---|
文档参考 | 文档参考<应用程序模型类型,Db模型类型> | 对要更新的文档的引用。 |
场地 | 字符串|字段路径 | 要更新的第一个字段。 |
价值 | 未知 | 第一个值。 |
更多字段和值 | 未知[] | 附加键/值对。 |
返回:
这
此Transaction
实例。用于链接方法调用。
例外情况
错误 - 如果提供的输入不是有效的 Firestore 数据。