I have the following code below, following the example of this link: https://gist.github.com/CodingDoug/814a75ff55d5a3f951f8a7df3979636a .Only that is returning error.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
exports.alertHelp = functions.firestore
    .document('chamados/{userId}')
    .onWrite(async (change, context) => {
        try {
            const snapshot = change.after;
            const val = snapshot.data();
            const tid = val.tid;
    
            const collection = db.collection('permissons');
            const query = await collection.where('tid', '==', tid).get();
            const token = query.data().fcmToken;
            const promises = [];
            token.forEach(fcm => {
                const p = admin.firestore().doc(`{userId}/${fcm}`).get();
                promises.push(p);
            });
            const snapshots = await Promise.all(promises);
            const results = [];
            snapshots.forEach(snap => {
                const data = snap.data().fcmToken;              
                results.push(data);
            })
            console.log(results);
            
        } catch (error) {
            console.error(error)
            
        }
     
});
Error
query.data is not a function
 
    