Skip to main content

Command Palette

Search for a command to run...

Check Firestore Function Type

Updated
•1 min read•View as Markdown
Check Firestore Function Type

Check Firestore Function Type

library_books Check Firestore Function Type

2 min read

[

Jonathan Gamble

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


library_books Firestore Full Text Search Package

6 min read


More from this blog

Code.Build

331 posts