Android firebase firestore&functions pushNotification using fcm token error

Solution for Android firebase firestore&functions pushNotification using fcm token error
is Given Below:

I have been working on firebase functions for whole day after upgrading the project,
what I want is to pushNotification to the token of the firestore document users,

This is my db structure

EX: when the collection Visitor doc change,push message to the token inside the doc
enter image description hereenter image description here

exports.vsUp = functions.firestore.document("Visitor/{docId}").onUpdate(
    (snapshot, context) => {
            result => {
                var registrationTokens = [];
                    tokenDocument => {
                    tokens: registrationTokens,
                    notification: {

This is my functions.js code right now,and it is not working,

How can a acheive what I want to do?

This line won’t work:


The {token} bits in here are just interpreted as literal strings. And since there’s no collection/document with that name, you get no results.

If you want to load all tokens for the user that is indicated in the request, it’d look something like this:


So you can see that:

  • This uses ` to mark the string, so that it’s interpreted as a template by JavaScript. You don’t need to do that on the first line, as that one is interpreted by Firebase itself when you deploy the Cloud Function.
  • The path now consists of three parts, so that it points to a collection, instead of the four in your code, which means it points to a document.
  • We use ${context.params.docId} to get the value of docId that triggered our Cloud Function.

Note that there may be many more reasons why messages are not delivered to the device, but these were definitely some of the reasons why your code was not reading anything from Firestore.