【发布时间】:2019-03-26 13:41:24
【问题描述】:
我目前正在尝试修改我的 Cloud Functions 并移入 https.onRequest 下,以便我可以调用使用它来安排 cron 作业。我如何在日志中收到以下错误。
TypeError: admin.database.ref 不是函数 在exports.scheduleSendNotificationMessageJob.functions.https.onRequest (/user_code/index.js:30:20) 在 cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:57:9)
exports.scheduleSendNotificationMessageJob = functions.https.onRequest((req, res) => {
admin.database.ref('/notifications/{studentId}/notifications/{notificationCode}')
.onCreate((dataSnapshot, context) => {
const dbPath = '/notifications/' + context.params.pHumanId + '/fcmCode';
const promise = admin.database().ref(dbPath).once('value').then(function(tokenSnapshot) {
const theToken = tokenSnapshot.val();
res.status(200).send(theToken);
const notificationCode = context.params.pNotificationCode;
const messageData = {notificationCode: notificationCode};
const theMessage = { data: messageData,
notification: { title: 'You have a new job reminder' }
};
const options = { contentAvailable: true,
collapseKey: notificationCode };
const notificationPath = '/notifications/' + context.params.pHumanId + '/notifications/' + notificationCode;
admin.database().ref(notificationPath).remove();
return admin.messaging().sendToDevice(theToken, theMessage, options);
});
return null;
});
});
【问题讨论】:
标签: javascript node.js firebase firebase-realtime-database google-cloud-functions