-
flutter batch 사용flutter 2021. 10. 27. 16:16
String docsUid = await _db
.collection('posts')
.add(post.toMap() as Map<String, dynamic>)
.then((docs) => _db.collection('posts').doc(docs.id).id);--> 파이어베이스에 1개의 문서를 입력하고 그 도큐먼트 id를 저장했다.
var ref = _db.collection('posts').doc(docsUid);
WriteBatch writeBatch = _db.batch();-> 쓰기 배치 인스턴스를 생성했다.
var wrongRef = _db.collection('postssssss').doc(docsUid);-> 존재하지 않는 경로의 레퍼런스를 일부러 할당해봤다.
writeBatch.update(wrongRef, {'postUid': docsUid}); --> 존재하지않는 문서이니 수행되지 않는다.
writeBatch.update(ref, {'postUid': docsUid});
writeBatch.delete(ref);
writeBatch.commit();--> 1개의 작업이 실패했으니 나머지 작업도 수행되지 않았다.
작업이 만약 전부 유효하다면 최종적으로 commit 함수를 호출해야 일괄 입력이 된다.
'flutter' 카테고리의 다른 글
[메모] flutter const, final (0) 2021.11.17 [메모 스크랩] bloc state는 항상 불변이어야하는가? (0) 2021.11.17 키보드 고정 UI (0) 2021.09.08 flutter 텍스트 폰트크기 고정 (0) 2021.09.08 appbundle 뽑다 오류 (0) 2021.08.07