Cloud Firestore Function Javascript: Triggering a function with whereEqualTo query

1880 views javascript

In Android we can listen inside a collection with simple queries/compound queries by setting a query like this.

mQuery = mDatabase.collection("Users")
            .orderBy("time", Query.Direction.DESCENDING)

Then setting a listener based on that Query like this.

 mQuery.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()){...

Can I do similar things with Cloud Function? I am currently using this line of code and it is working.

functions.firestore.document("Users/{user_id}/Notifications/{notification_id}").onCreate((added, context) => {

But for some changes, now I would like to trigger a function only where document field is equal to something then for loop I think?

Another thing is how am I going to get the document Id of 'Notification' collection now if queries is possible, now I use wild card then retrieving it like this.

const notification_id = context.params.notification_id;

answered question

1 Answer


With Cloud Functions triggers for Firestore, you can only specify which collections and documents cause the function to fire by using wildcards. There are no query filters available. If you want to further restrict which changed documents require some action, you have to check the contents of the document in your code.

posted this

Have an answer?


Please login first before posting an answer.