Cloud Functions is a feature provided by Firebase for running server codes at Google infrastructures in response to events triggered by Firebase events and HTTPS requests.
Cloud Functions is a feature provided by Firebase for running server codes at Google infrastructures in response to events triggered by Firebase events and HTTPS requests. Developer does not have to handle the maintenance and scalability issues. Firebase automatically scales up computing resources to match the usage patterns of your users. Each function runs in isolation in its own environment with its own configuration.Developer just has to write the business logic and let Google handle the server for us.
There are a lots of available Firebase events and one of them is Firestore event. Firestore notifies Cloud Functions once any document is created, updated and deleted within the specific collection. It is useful for adding extra information at document initialisation, validating information when document is updated and notifying admins / users once their information is deleted.
The implementation is not difficult but with some tricks. Lets see here!
const functions = require("firebase-functions")
/*
Example of new data: {
'fooKey': 'fooValue'
}
*/
exports.onCreateTrigger = functions.firestore
.document('fooCollection/{docId}')
.onCreate((queryDocumentSnapshot, eventContext) => {
// ID of newly created document
const newlyCreatedDocumentID = eventContext.params.docId
// Retrieve value from data
const createdData = queryDocumentSnapshot.data();
const fooValueSyntax1 = createdDate.fooKey;
const fooValueSyntax2 = createdDate["fooKey"];
const fooValueSyntax3 = queryDocumentSnapshot.get("fooKey");
return 0
});
view raw
OnCreateTrigger.js hosted with ❤ by GitHub
onCreate
is triggered once a new document in a specific collection ( fooCollection
at line 8) is created. The callback contains a QueryDocumentSnapshot
and an EventContext
. Document id and document data can be retrieved from them for further checking (See line 11 to line 17).
google firebase-cloud-functions firestore firebase gcp function
Mismanagement of multi-cloud expense costs an arm and leg to business and its management has become a major pain point. Here we break down some crucial tips to take some of the management challenges off your plate and help you optimize your cloud spend.
If you looking to learn about Google Cloud in depth or in general with or without any prior knowledge in cloud computing, then you should definitely check this quest out.
**Link: https://www.youtube.com/watch?v=gud65lqebrc** In this [**Google Cloud Training**](https://www.youtube.com/watch?v=gud65lqebrc "Google Cloud Training") live session, you will know everything about google cloud from basic to advance level...
What is Google Cloud? The Google cloud platform provides its users with stable and highly scalable cloud computing services. These services help customers compute and store information and help developers...
Hi, Spring fans! In this episode, Josh Long (@starbuxman) talks to Google Cloud’s Elena Felder (@hellata) about building Reactor/Spring-based integrations for Google Cloud technologies like Google Cloud Spanner. Bootiful Podcast: Google Cloud's Elena Felder on Spring Cloud GCP, Reactor, and More