【发布时间】:2019-06-07 21:50:01
【问题描述】:
我创建了一个 Firebase 函数来触发推送通知,但我在 Firebase 上获得了以下寄存器,“函数返回未定义、预期的 Promise 或值”和“snapshot.docs 在 admin.firestore.collection.get.then 中不可迭代(/srv/index.js:20:38)"。你们有什么解决办法吗?
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var msgData;
exports.destaquesTrigger = functions.firestore.document(
'destaques/{destaquesId}'
).onCreate((snapshot, context) => {
msgData = snapshot.data();
admin.firestore().collection('pushtokens').get().then((snapshots) =>
{
var tokens = [];
if (snapshots.empty) {
console.log('No Devices');
} else {
for (var token of snapshot.docs) {
tokens.push(token.data().devtoken);
}
var payload = {
"notification": {
"title": msgData.notif1,
"body": msgData.notif2,
"sound": "default"
},
"data": {
"sendername": msgData.notif3,
"message": msgData.notif4,
}
}
return admin.messaging().sendToDevice(tokens,
payload).then((response) => {
console.log('Pushed them all');
}).catch((err) => {
console.log(err);
})
}
})
})
错误:
6:22:54.175 PM destaquesTrigger Function execution started
6:22:54.175 PM destaquesTrigger Billing account not configured.
External network is not accessible and quotas are severely
limited. Configure billing account to remove these restrictions
6:22:54.676 PM destaquesTrigger Function returned undefined,
expected Promise or value
6:22:57.168 PM destaquesTrigger Function execution took 2993 ms,
finished with status: 'ok'
6:23:23.652 PM destaquesTrigger Unhandled rejection
6:23:23.752 PM destaquesTrigger TypeError: snapshot.docs is not
iterable at admin.firestore.collection.get.then
(/srv/index.js:20:38) at <anonymous> at
process._tickDomainCallback (internal/process/next_tick.js:229:7)
【问题讨论】:
标签: javascript firebase google-cloud-functions