Write Cloud Functions on Cloud Firestore and deploy – Introduction
Node.js , databases , firestore / May 16, 2019

Contents > What is Cloud Firestore >What are Cloud functions >Writing and Deploying Cloud Functions to write data to Cloud Firestore Collection What is Cloud Firestore It’s a NoSQL document database that lets you store data for your Mobile Application, web Application, APIs… It is Cloud-based, highly scalable and flexible. To see your Firestore database dashboard visit the below URL https://console.firebase.google.com/project/YOURPROJECTNAME/overview Firestore has the following Datatypes string number boolean map array null timestamp geopoint reference Firestore is a Document database.We can save data as collections -> documents  ->  subcollections in a nested structure. Here we can see that the created date is a timestamp ,reciever_data is a map and reciever_id is a string data. What are Cloud functions Cloud Functions help to achieve serverless execution by providing access to Firebase and Cloud events .Operations can be done in response to these events. For example, you can do CRUD operations on the Firestore / Realtime database using Cloud Functions. You can deploy the Cloud function and hit them to perform these CRUD operations. The event handler for an HTTP request to the Cloud Functions listens for the onRequest event Writing and Deploying Cloud Functions to add data to Cloud Firestore Collection step 1…

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