我的firestore云功能遇到问题。我正在尝试设置一个触发器,以便在添加新文档时发送通知。
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
/*exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello ninjas!");
});*/
// Function to be called when new event occurs
const createNotification = notification => {
return admin
.firestore()
.collection("notifications")
.add(notification)
.then(doc => console.log("Notification added", doc));
};
//Trigger when new project is created
exports.projectCreated = functions.firestore
.document("project/{projectId}")
.onCreate(doc => {
const project = doc.data();
const notification = {
content: "Added a new project",
time: admin.firestore.FieldValue.serverTimestamp()
};
return createNotification(notification);
});
在客户端,当我添加新项目时,我可以看到添加通知的控制台消息,但当我在Cloud功能中检查日志时,我看不到任何日志。我是不是遗漏了什么?
更换
.onCreate(doc => {
带有
.onCreate((snap, context) => {
如中所述
https://firebase.google.com/docs/functions/beta-v1-diff#cloud-消防仓库