0

I have a JSON file that looks like this:

const data = [
    {
        name: 'Dry Ice',
        total: 84,
        price: 346,
    },
    {
        name: 'Chef Hat 20cm',
        total: 156,
        price: 231,
    },
   // and more data
]

I want to add all objects in a firestore collection as documents.

I have found batch operation documentation. They show how to update the existing documents. But I want to create new documents in one request from the client side.

  • The documentation you linked shows you how to create documents with the set operation. Have you tried? A batch set operation works just like a [normal set](https://firebase.google.com/docs/firestore/manage-data/add-data#set_a_document), except all at once. – Doug Stevenson Jun 05 '22 at 18:27
  • Checkout the linked answer. `batch.set(...)` instead of `batch.update(...)` should do as Doug mentioned. – Dharmaraj Jun 05 '22 at 18:39

0 Answers0