dormitkon
dormitkon

Reputation: 2526

Atomic write of 2k+ documents in Firestore

I have a use case where I want to create: 1 document, which has a collection "locations" which needs to have more than 2000 documents.

Every document has 4-5 fields, nothing huge, but every document is its own network request, and it takes ages to create them on Firestore.

Is there any better way to do this? Batched writes have up to 500 object creations limit and support set, update and delete (not create).

Upvotes: 0

Views: 160

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 138824

The most appropriate solution for this problem is to use batch operations. So you can execute multiple write operations as a single batch even if you are only using the set() method, which actually adds a document at specific reference. The single issue in here is that you cannot add more than 500, so you should create a mechanism to add all 2000 documents in 500 chunks. So 4 batch operations will be needed.

Upvotes: 3

Related Questions