node.js - 更新 Firestore 文档中的所有字段
问题描述
我想一次更新文档中的所有记录。即使我只更改了表单中的一个值,我也会将整个表单数据从角度服务发送到此云功能。我已经能够成功编写获取所有用户并一次获取一个用户的云功能,但我对更新功能有点困惑。这是我的创建功能
创建客户
exports.addClient = functions.https.onRequest((req, res) => {
if(req.body.company != null && req.body.abbrev != null && req.body.contact != null && req.body.phone != null && req.body.email != null && req.body.contactDate != null ||
req.body.company != undefined && req.body.abbrev != undefined && req.body.contact != undefined && req.body.phone != undefined && req.body.email != undefined && req.body.contactDate != undefined) {
let docId = Math.floor(Math.random() * (99999 - 00000));
let newClient = {
"company": req.body.company,
"abbrev": req.body.abbrev,
"contact": req.body.contact,
"phone": req.body.phone,
"email": req.body.email,
"contactDate": req.body.contactDate
}
usersClients.add(newClient).then(snapshot => {
res.send(200, {
"message": "Client was successfully created"
})
});
} else {
res.send(400, {
"message": "All fields are required"
})
}
});
我如何编写将一次更新上述创建的云函数的所有值的函数。
解决方案
推荐阅读
- events - Laravel Eloquent 模型观察者删除方法抛出异常。怎么了?
- python - 扫雷算法,从起始方格打开所有相互接触的安全方格
- object - 无法在 Kotlin 中对象的超类构造函数中使用常量
- nvidia - 无法在每帧上获得 secondary1-nvinference-engine 和 secondary2-nvinference-engine 的结果
- django-rest-framework - 在返回 DRF 之前更改查询集
- github - 如何通过命令行从公共 github 存储库下载二进制文件?
- sql - OperationalError:尝试在 Google Cloud 应用程序上写入只读数据库
- node.js - 如何用变量替换所有内容?
- python - 在部分 COCO 数据集上训练 Detectron2
- json - 文件响应中的奇怪字符