Reputation: 12385
I'm confused by the Firestore documentation on deletes. The documentation says:
There is also no guarantee that the delete operations will succeed or fail uniformly, so be prepared to handle cases of partial deletion... There is no operation that atomically deletes a collection.
https://cloud.google.com/firestore/docs/solutions/delete-collections
I don't know if the above statement only refers to the cloud function in the example or performing large-scale deletes in general.
Batch writes can perform deletes, however, and they are atomic. Therefore, if a collection with fewer than 500 documents (the batch-write operation limit) ran a batch-write operation of deletes, would that not be an atomic collection delete? The documentation on batch writes doesn't lend clarification because it doesn't state that a batch of operations completes atomically, only writes. I cannot surmise if this is intentional.
A batch of writes completes atomically and can write to multiple documents.
https://cloud.google.com/firestore/docs/manage-data/transactions
Deleting entire collections aside (because I know the caveats that come with that), is performing deletes in a batch write atomic?
Upvotes: 0
Views: 297
Reputation: 317372
I don't know if the above statement only refers to the cloud function in the example or performing large-scale deletes in general.
It applies to both. Both situations involve making multiple calls to delete all documents, and those calls might each succeed or fail, leaving the collection in an inconsistent state (partial deletion). A second wave of operations would be required to clean up the rest of the documents.
A batch delete of 500 or fewer documents will, on the other hand, give you the guarantee of all-or-none behavior for a single batch. But if you had more than 500 to delete, it would require multiple batches, and now you're back to the same problem above - any number of them could succeed or fail, and you'll need to handle that.
Upvotes: 1