我正在尝试制作我的第一个 Firebase 云功能。 我想添加名称字段的值 - 该字段位于 ahmed 文档内的 'amr' 文档中,字段名称为 newName 。我做了这个功能,但每次它都会给出错误或不显示任何内容 我的函数有什么问题
const functions = require('firebase-functions');
const admin=require('firebase-admin');
admin.initializeApp();
exports.myfunc=functions.firestore.document('Users/amr').onWrite((change,context)=>{
const name=change.data().name;
return admin.firestore().document('Users/ahmed').add({newName:name});
});
最佳答案
更改此:
const name=change.data().name;
进入此:
const name=change.after.data().name;
写入后能够检索数据
更多信息在这里:
https://firebase.google.com/docs/functions/beta-v1-diff#cloud-firestore
关于javascript - 第一次尝试firebase云功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51252498/