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 :: angular closest element 
Typescript :: jasmine test button click 
Typescript :: when i console log a obj its printing object 
Typescript :: angular mailto on button click 
Typescript :: alert angular 
Typescript :: mysqli_fetch_array() expects parameter 1 to be mysqli_result 
Typescript :: VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead. 
Typescript :: methods defined as testmethod do not support web service callouts 
Typescript :: reactnative upload image axios 0.66 
Typescript :: typescript enum to string 
Typescript :: node fetch image to base64 
Typescript :: Keras cheatsheets pdfs 
Typescript :: how to get value from autocomplete material ui 
Typescript :: linq check if exists in list 
Typescript :: file_exists in wordpress 
Typescript :: add comma for input number automatically typescript 
Typescript :: How to Solve Property ‘getContext’ does not exist on type ‘HTMLElement’ error in Angular 12 & TypeScript 
Typescript :: how to declare an empty array in typescript 
Typescript :: typescript for loop key value pai 
Typescript :: typescript type function callback in interface 
Typescript :: Cannot show Automatic Strong Passwords for app bundleID: com.williamyeung.gameofchats due to error: iCloud Keychain is disabled 
Typescript :: event type typescript angular 
Typescript :: angular rxjs mergemap 
Typescript :: append contents of one file to another 
Typescript :: find unique values between 2 lists R 
Typescript :: typescript interface vs type 
Typescript :: nestjs mongoose schema nested 
Typescript :: typescript get types from arrays 
Typescript :: typescript datetimte 
Typescript :: Lire un fichier de valeurs séparées par des points (csv) dans DataFrame 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =