我在本教程中有以下示例函数:Asynchronous Programming (I Promise!) with Cloud Functions for Firebase - Firecasts
exports.emailEmployeeReport = functions.database
.ref('/employees/${eid}/reports/${rid}')
.onWrite(event => {
const eid = event.params.eid;
const report = event.data.val().report;
const root = event.data.ref.root;
const mgr_promise = root.child(`/employees/${eid}/manager`).once('value');
const then_promise = mgr_promise.then(snap => {
const mgr_id = snap.val();
const email_promise = root.child(`/employees/${mgr_id}/email`).once('value');
return email_promise;
}).catch(reason => {
// Handle the error
console.log(reason);
});;
const then_promise2 = then_promise.then(snap => {
const email = snap.val();
const emailReportPromise = sendReportEmail(email, report);
return emailReportPromise;
}).catch(reason => {
// Handle the error
console.log(reason);
});
return then_promise2;
});
var sendReportEmail = function (email, report) {
const myFirstPromise = new Promise((resolve, reject) => {
// do something asynchronous which eventually calls either:
//
setTimeout(function () {
try {
var someValue = "sendReportEmail";
console.log(someValue);
// fulfilled
resolve(someValue);
}
catch (ex) {
// rejected
reject(ex);
}
}, 2000);
});
return myFirstPromise;
}
一旦我运行firebase deploy
命令,最终我得到以下错误:
functions [emailEmployeeReport]:部署错误:配置失败 触发 providers/google.firebase.database/eventTypes/ref.write@firebaseio.com (emailEmployeeReport)
我还有一个简单的hello-world方法和一个类似的触发器方法,它们部署得很好。
我在这里错过了什么吗?
答案 0 :(得分:4)
数据库引用中通配符的语法没有“$”。
尝试以下方法:
exports.emailEmployeeReport = functions.database .ref('/ employees / {eid} / reports / {rid}')