How to trigger Firestore ?

Sudish Kumar
Jan 17, 2021

--

In this story we will cover trigger on firestore .We will use JavaScript for trigger firestore.

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();

exports.getData = functions.https.onRequest((req, res) => {
const docRef = db.collection('collectionName).doc('document')
const getDoc = docRef.getData()
.then(doc => {
if (!doc.exists) {
console.log('No such document!');
return res.send('Not Found')
}
console.log(doc.data());
// res.status(200).json(doc.data())
return res.send(doc.data());

})
.catch(err => {
console.log('Error getting document', err);
});
});
exports.storageChanges = functions.storage.object().onArchive(event => {
return res.send(event.getData());
});

Thank you for reading this story👍👍👍👍👍

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sudish Kumar
Sudish Kumar

Written by Sudish Kumar

Flutter | Android | Node | Dart | Kotlin | Java | JavaScript | TypeScript | PHP | Short Story Teller | Tech Lead

No responses yet

Write a response