-
-
Notifications
You must be signed in to change notification settings - Fork 5
Firestore Transactions and Batched Writes
The contents of this page are based on the original Firebase Documentation
If you do not need to read any documents in your operation set, you can execute multiple write operations as a single batch that contains any combination of set(), update(), or delete() operations. A batch of writes completes atomically and can write to multiple documents.
Batched writes are also useful for migrating large data sets to Cloud Firestore. A batched write can contain up to 500 operations and batching operations together reduces connection overhead resulting in faster data migration.
Batched writes have fewer failure cases than transactions and use simpler code. They are not affected by contention issues, because they don't depend on consistently reading any documents. Batched writes execute even when the user's device is offline. The following example shows how to build and commit a batch of writes:
// Get new write batch
var batch:WriteBatch = db.batch();
// Set the value of 'NYC'
var nycRef:DocumentReference = db.collection("cities").document("NYC");
batch.setData({}, nycRef);
// Update the population of 'SF'
var sfRef:DocumentReference = db.collection("cities").document("SF");
batch.updateData({"population": 1000000 }, sfRef);
// Delete the city 'LA'
var laRef:DocumentReference = db.collection("cities").document("LA");
batch.deleteDocument(laRef);
batch.commit(function(error:FirestoreError):void{
});
Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.
Project setup
Analytics
Authentication
Dynamic Links
Google Sign In
Firestore
- Configuring the ANE
- Get Started
- Add and Manage Data
- Query Data
- Get Data
- Get Realtime Updates
- Perform Simple and Compound Queries
- Order and Limit Data
- Paginate Data
Messaging
One Signal
Performance
Remote Config
Storage
- Configuring the ANE
- Get Started
- Create a Reference
- Upload Files
- Download Files
- Use File Metadata
- Delete Files
Crashlytics
Vision
- Detect faces
- Scan barcodes
- Label images
- Recognize landmarks
- Natural Language
- Custom Models
External Links