我的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功能中的日志时,我看不到任何日志。我在这里想念什么吗?
答案 0 :(得分:0)
替换
.onCreate(doc => {
使用
.onCreate((snap, context) => {
如
所述https://firebase.google.com/docs/functions/beta-v1-diff#cloud-firestore