Check Firestore Function Type


library_books Check Firestore Function Type
2 min read
[

jdgamble555 on Tuesday, November 24, 2020 (last modified on Saturday, October 15, 2022)
](https://code.build/u/86qJ3nXSvhBPUbmdaMwUeb/jdgamble555)
Sometimes you want to check what kind of onWrite() function you are dealing with in Firestore:
functions.firestore .document('posts/{docId}') .onWrite(async (change: any, context: any) => { //... code }
So, I created some simple functions to find out. First install the package:
npm i adv-firestore-functions
Then import the functions you want:
import { createDoc, updateDoc, deleteDoc } from 'adv-firestore-functions';
or for more complex checks like:
writeDoc = createDoc || updateDoc
shiftDoc = createDoc || deleteDoc
popDoc = updateDoc || deleteDoc
import { writeDoc, shiftDoc, popDoc } from 'adv-firestore-functions';
And use it like so:
if (createDoc(change)) { // a document is being created, so do something... }
Simple.
J




