是否可以同时运行Firestore和Firebase-Storage的事务和批处理写入?

问题描述 投票:0回答:1

Use-Case:我必须在单个[中编写一些document_1更新,并使用Transactions和分批写入。可能吗?如果可能的话如何? [[Note

:完成时所有四个异步任务都应该成功,否则所有四个任务都应该失败。如果只能读写大小写,则此Transactions and batched writes documentation可以提供帮助。但是在我们的例子中,文件读取-上传-删除任务也是如此。

Future<void> _runTransaction() async { firestore.runTransaction((Transaction transaction) async { final allDocs = await firestore.collection("messages").getDocuments(); final toBeRetrieved = allDocs.documents.sublist(allDocs.documents.length ~/ 2); final toBeDeleted = allDocs.documents.sublist(0, allDocs.documents.length ~/ 2); await Future.forEach(toBeDeleted, (DocumentSnapshot snapshot) async { await transaction.delete(snapshot.reference); }); await Future.forEach(toBeRetrieved, (DocumentSnapshot snapshot) async { await transaction.update(snapshot.reference, { "message": "Updated from Transaction", "created_at": FieldValue.serverTimestamp() }); }); }); await Future.forEach(List.generate(2, (index) => index), (item) async { await firestore.runTransaction((Transaction transaction) async { await Future.forEach(List.generate(10, (index) => index), (item) async { await transaction.set(firestore.collection("messages").document(), { "message": "Created from Transaction $item", "created_at": FieldValue.serverTimestamp() }); }); }); }); }

用例:我必须使用事务和批处理写入的单个事务在document_2中写入一些document_1更新,并从document_storage中删除document_3和delete file_4。是...
firebase google-cloud-firestore transactions firebase-storage file-storage
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.