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

March 17, 2019

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

STEP 2

Create the  reference to the collection in which you are going to add the batch data

STEP 3

Post batch data as an array to the Express server you have created.

STEP 4

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 *