simple firestore cloud function update document

Solutions on MaxInterview for simple firestore cloud function update document by the best coders in the world

showing results for - "simple firestore cloud function update document"
Aymeric
24 Feb 2018
1import * as functions from 'firebase-functions';
2import * as admin from 'firebase-admin';
3
4admin.initializeApp();
5
6export const resetCounter = functions.https.onRequest((req, res) => {
7    const resetRef =  admin.firestore()
8    .collection('collectionName')
9    .doc('documentName')
10    resetRef.get().then((doc) => {
11        if(doc.exists){
12            resetRef.update({counter: 0})
13              .catch(err => {
14            console.log("Error",err)
15            res.send("500");
16          })
17       }
18    }).catch(err=>{
19      	//Internal server error
20      	console.log("Error",err)
21        res.send("500");
22    });
23  //Successful operation
24  res.send("200");
25});
Jamal
28 Jun 2016
1import * as functions from 'firebase-functions';
2import * as admin from 'firebase-admin';
3
4admin.initializeApp();
5
6export const setProductsToExpired = functions.https.onRequest(async(request, response) => {
7    const expiredProducts = await admin.firestore()
8      .collection('products')
9      .where('timestamp','<=', admin.firestore.Timestamp.now())
10      .get();
11    
12    const batch = admin.firestore().batch();
13 
14    expiredProducts.forEach(doc => {
15      batch.update(doc.ref,'expired',true);
16    });
17    
18    await batch.commit();
19    //Successful operation
20    response.send("200");
21    });
similar questions
firestore increment field
queries leading to this page
firestore cloud functions update documenthow to update a doc in firestoreaccess collections from firebase functionsfirebase functions react on firestore changesfirestore write methods for cloud functionsfirestore update where document javascriptcloud functions get from firestorewrite to firestore from cloud functionupdate a document in firestoreget data on update firestore document cloud functionsfirebase firestore cloud function doc setfirebase cloud functions on creteupdate document firestore fonctionfirebase function to update firestorecloud functions update firestorefirebase update document in firestore using cloud functionuse firestore in firebase functionsfirebase on document add cloud functionpayload function firestoreadd data to firestore firestore functionsfirestore cloud function get onefirebase functions write to firestorefirestore update document tutorialupdate document on trigger firestorecloud functio firestore examplehow to firestore cloud function insert document into collectionfiresrtore cloud functionfirebase save own userdata cloud firestoreread from firestore cloud functionhow to use cloud functions in firestorefirestore cloud function get documentrun firestore trigger in express functionscan i use firestore in cloud functionconnection firebase function to firestorecreate a document in collection using cloudfunctionfirebase cloud functions firestorecloud function update other documnets exampleupdate usinng where cloud firestorefirebase functions create documentcloud functions for firebase connect to firestorefirebase cloud function read firestorecloud functions add documentupdate value firestore cloud functioncloud firestore function update documentcloud functions for firestorecloud functions with firestoreupdate document in firestore cloud functionsfirestore functions update document on createcant change cloud firestore rulescloud firestore function calluse firestore in cloud functionsextend class firestore nodejscloud functions write to firestorecloud functions and firestore retrievehow to add a collection through firebase functiondcoument update firestore cloud functionfirebase firestore cloud function examplefirestore function on document write change cloud firestore function updatedocumentfirestore document update triggerfirebase functions update firestore documentupdate documents firestorecloud function trigger firestore document changefirestore data 28 29 functionfirebase function connetc firetstoreupdate all documents in collection firestore when user changes namecloud firestore alter documentcloud firestore functionfirestore see cloud functionscloud function firestore createupdate document firestorecloud functions create all documentsfirestore cloud function params idupdate specific document firestorefirebase firestore update methodfirestore function custom setfirebase realtime data update with firestore cloud functionsfirestore setdata objectcloud functions to 27subscribe 27 to documents firebasefirestore build a like functionaccess firestore from cloud functions import databsecloud function write to firestore e examplefirebase functions firestore getfirestore cloud functions examplecloud functions firestore migrate to javascriptupdate item firestore cloud funcitonaccess firestore from firebase functionscloud function write to firestore e amplefirestore cloud functions example jshow to update on firestore from cloud functiosfirestore update documentupdate document id firestore xamarincloud functions triggers firestorefirestore function setfirestore functions for eachfirestore function set javascriptfirebase function firestore getchange document id firestore cloud xamarinfirebase functions firestoreupdating cloud firestore document with setdocument onwrite firestore cloud functionscloud firestore update documentupdate firestore cloud functionsfirestore cloud function update documentsfirebase firstore cloud functionsfirebase cloud functions how to add data to firestorefirebase cloud function firestore addfirestore cloud functions example whereget method firestore cloud functionshow to use cloud functions in firestore to keep data syncgoogle cloud functions with firestoresimple firestore cloud function update documentfirestore function write to single documentfirestore api cloud functionfirestore on update cloud functionfirestore cloud funtion documentaionfirestore function write customfirebase functions update firestoreupdate firestore cloud methodfirestore update field with cloud functioncan i write firestore functions languageupdate firestore document with new fieldwrite function in firestorefirestore get functionscloud function update firestore documentupdate firestore doc functionsfirebase cloud functions on doc additionhow to create a collection through firebase function and add a document at same timehow to get nodejs firestore document firebase functionsfirestore write from cloud functionfirebase on create firestore cloud functionset data from cloud functionsfirebase cloud functions create documentcloud firestore functionsfirestore update documentsfirebase update firestore document from cloud functiongoogle firestore cloud functionsfirestore cloud functionshow to get firestore updated documents from cloudconnect from firebase functions to firestorehow to use cloud functions in firestore to keep data snyxfirestore with cloud functionsfirestore cloud update documentfirebase function call on document changefirestore cloud functions firebasecall firestore inside a functionwhy cant i use firestore in override function androidfirestore document updategoogle firestore functions languagefirestore cloud functions get collection on conditionfirebase cloudfirestore functions javascriptfirestore function update documentfirestore cloud functions examplesfirebase functions get firestore data from on call functionfirebase functions firestoragefirestore functions wherecloud function get firestorefirestore cloud function if do exists update another doccloud firestore firebase functionswhy firestore isnt adding data cloud functionfunctions in firebase database and firestore webupdating a document in firestore collectionfirestore js functionsfirestore update javascriptaccess firestore from cloud functionsfirestore write method for cloud functionsupdate document firebase cloud xamarinwhat is a function for firestorefirebase cloud functions on doc addcloud function access doc datafirestore update or create document cloud functionshow to write a firestore update functionfirestore from cloud functionsfirestore cloud function update valuefirestore update document fieldfirestore cloud function update documents for loopfirebase cloud function firestoretutorial cloud functions firestorefirestore update document methodfirebase cloud functions update firestoreextend class firestorefirebase cloud function write to firestorefirestore cloud functions firestorefirebase firestore funcitonshow to update on data firestore from cloud functionsfirebase functions get information about document in cloud firestorecloud function firestore vs firestore 28 29firestore create collection functionhow to know when a cloud firestore function is donehow to add functions in firestoreadmin firestore 28 29 collection 28 27messages 27 29 where in js for cloud functionswrite function to firestorefirestore cloud functions example contains firebase firestore cloud functionsfirestore cloud function update documents foeachdata function firestorefirestore update any document wherefirestore and cloud functions in same repository 3f firestorefirestore update document cloud functionspecify data type for firestore in expresssimple firestore cloud function update document