Batch add to Google Cloud Firestore database collection : Node.js and Express

STEP 1 – InitializeFirestore App

To initializeFirestore, get the key file from your Google cloud console and save it in a folder. Install the Firebase admin module

Now to initialize app, use the following code


Post batch data as an array to the Express server you have created. The JSON sent to the server has the following structure with key ‘user’ having an array of users.


Loop over the req.body using forEach and set each data to be added into the collection using the set method

Commit the data and save the data to the collection using the commit method and on success, send a success response.

The full code is as follows


No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *