Transaction class

對交易的引用。

傳遞給交易的updateFunctionTransaction物件提供在事務上下文中讀取和寫入資料的方法。參見runTransaction()

簽名:

export declare class Transaction 

方法

方法修飾符描述
刪除(文件參考)刪除所提供的DocumentReference引用的文檔
取得(文件參考)讀取所提供的DocumentReference引用的文檔
設定(文件參考,數據)寫入所提供的DocumentReference引用的文檔。如果該文件尚不存在,則會建立該文件。
設定(文件參考、資料、選項)寫入所提供的DocumentReference引用的文檔。如果該文件尚不存在,則會建立該文件。如果您提供mergemergeFields ,則提供的資料可以合併到現有文件中。
更新(文件參考,數據)更新所提供的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引用的文檔。如果該文件尚不存在,則會建立該文件。如果您提供mergemergeFields ,所提供的數據可以合併到現有文件中。

簽名:

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