firebase cloud method update
firebase deploy --only functions:functionNameHere
firebase cloud method update
firebase deploy --only functions:functionNameHere
simple firestore cloud function update document
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
export const resetCounter = functions.https.onRequest((req, res) => {
const resetRef = admin.firestore()
.collection('collectionName')
.doc('documentName')
resetRef.get().then((doc) => {
if(doc.exists){
resetRef.update({counter: 0})
.catch(err => {
console.log("Error",err)
res.send("500");
})
}
}).catch(err=>{
//Internal server error
console.log("Error",err)
res.send("500");
});
//Successful operation
res.send("200");
});
firestore cloud function update documents
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
export const setProductsToExpired = functions.https.onRequest(async(request, response) => {
const expiredProducts = await admin.firestore()
.collection('products')
.where('timestamp','<=', admin.firestore.Timestamp.now())
.get();
const batch = admin.firestore().batch();
expiredProducts.forEach(doc => {
batch.update(doc.ref,'expired',true);
});
await batch.commit();
//Successful operation
response.send("200");
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us