首页 > 解决方案 > 更新 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"
        })
    }
});

我如何编写将一次更新上述创建的云函数的所有值的函数。

标签: node.jsgoogle-cloud-firestore

解决方案


推荐阅读