javascript - 第一次尝试firebase云功能
问题描述
我正在尝试制作我的第一个 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 - 在javascript中找不到树枝变量
- android - 禁用基于 sdk 版本的意图过滤器?
- rest - POST 的 RESTful API 中的多个路径参数与查询参数?
- ruby-on-rails - Yarn -v 给出了这个我无法理解的错误
- c# - 单选按钮 If..Then..Else 在文本框中显示单词
- postgresql - postgres:需要冻结 xid 截止之前未提交的 xmin
- python - ValueError:无法将字符串转换为浮点数:'2002–03'
- r - 如何删除tmap中的地图轮廓?
- python - 防止跨模块重复列表?
- c++ - 查找和比较两个字符串中的字符