Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

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");
});
Comment

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");
    });
Comment

PREVIOUS NEXT
Code Example
Typescript :: laravel unique working with softdeletes 
Typescript :: object.fromentries typescript 
Typescript :: bullets in latex with header 
Typescript :: nodejs aws s3 upload 
Typescript :: typescript string to number 
Typescript :: subplots matplotlib 
Typescript :: typescript slice string 
Typescript :: how to add lint is declared but its value is never read. 
Typescript :: beautify typescript nodejs 
Typescript :: ts singleton pattern 
Typescript :: append contents of one file to another 
Typescript :: how to check if data attribute exists in jquery 
Typescript :: access single document with its id flutter 
Typescript :: extending a type in typescript 
Typescript :: redux persist typescript 
Typescript :: typescript array of objects 
Typescript :: basic variable types typescript 
Typescript :: get type of element of array typescript 
Typescript :: how to count digits in python 
Typescript :: typescript convert string to character array 
Typescript :: typescript function return type observable 
Typescript :: input deno 
Typescript :: java check if element exists in array 
Typescript :: how to keep only certian objects python 
Typescript :: replace floats in dataframe 
Typescript :: angular sort string 
Typescript :: how to add custom snippets in emmet in visual studio code 
Typescript :: invoke lambda after cdk deploy 
Typescript :: type async function typescript 
Typescript :: test coverage techniques 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =