Batch add to Google Cloud Firestore database collection : Node.js and Express
Node.js , Express.js , databases / 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 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.

STEP 3 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

 

Share this page in social media platforms