對交易的引用。
傳遞給交易的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 資料。