Я развернул функцию со следующим запросом:
admin.firestore().collection("fcm").where("devices",'array-contains', mobile).get().then((snapshots)=> {...});
Это возвращает следующую ошибку из журнала функций облака:
msgTrigger: Function execution started
msgTrigger: Function returned undefined, expected Promise or value
msgTrigger: Function execution took 8429 ms, finished with status: 'ok'
msgTrigger: Unhandled rejection
msgTrigger: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined at admin.firestore.collection.where.get.then (/user_code/index.js:23:65) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
Кто-нибудь, пожалуйста?
Бои в течение нескольких дней с редактором здесь.решил опубликовать мой код функции по частям:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var msgData;
var mobile;
Вторая часть:
exports.msgTrigger = functions.firestore
.document('Messages/{MessageID}')
.onCreate((snapshot, context) => {
msgData = snapshot.data();
mobile = msgData.mobile;
admin.firestore().collection("fcm").where("devices", 'array-contains', mobile).get().then((snapshots) => {
Третья часть:
var tokens = [];
if (snapshots.empty) {
console.log('No devices');
} else {
for (var token of snapshot.docs) {
tokens.push(token.data().token);
}
var payLoad = {
"notification": {
"title": "de " + msgData.name,
"body": "Alerta de Emergência!",
"sound": "default",
"icon": msgData.icon
},
"data": {
"remetente": +msgData.name,
"mensagem": "Alerta de Emergência!"
}
}
Четвертая часть:
return admin.messaging().sendToDevice(tokens, payLoad).then((response) => {
console.log("mensagens enviadas");
}).catch((err) => {
console.log("erro: " + err);
});
}
});
});