javascript - Firestore 中的数据未更新

标签 javascript firebase google-cloud-firestore

这是一个 javascript 函数,旨在对 FireStore 执行更新,但该函数不起作用。

如果有人能看到代码中的问题,我会更高兴。

function makeUpdate(key,name) {
    let theCollection = db.collection("InformationList"),
    infoUnit = theCollection.doc(key).get().then(function(doc) {
        if (doc.exists) {
            console.log("infoUnit -name-:" + doc.get("name"));
            console.log("infoUnit -telephone-:" + doc.get("telephone"));
            let updateDico = {};
            updateDico["name"] = name;
            doc.update(updateDico);
        } else {
            console.log("embassyUpdate --> No such document!");
        }
    }).catch(err => {
        console.log("Error getting documents (in makeUpdate)", err);
    });
}

除了它没有执行预期的更新之外,它还在日志中打印了三条消息:

  • infoUnit -name-:一些名称
  • infoUnit -telephone-:一些电话号码
  • 获取文档时出错(在 makeUpdate 中)

从中我可以看到,按照预期在数据库中找到了一条记录。但同时发生了未知错误。

最佳答案

doc(DocumentSnapshot 对象)上没有 update() 方法。 DocumentSnapshot 仅包含从 get() 读取的数据。如果要将数据写回到文档中,则需要使用 DocumentReference对象,可能与您调用 theCollection.doc(key) 时获得的对象相同。

关于javascript - Firestore 中的数据未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53006590/

相关文章:

Firebase动态链接-自定义后缀

android - Firestore 数据的仪表板?

php - 管理面板 cms 的裁剪工具

javascript - Angular.js 中的 ng-repeat 未按预期工作

firebase 设置后台消息处理程序

firebase - Flutter-将图像上传到Firebase存储

firebase - 警告 : The behavior for java. 存储在 Firestore 中的 util.Date 对象将会更改

javascript - 将 XML 解析移至服务器端

javascript - 如何抽象一个JavaScript文件?

javascript - 如何用Javascript或C#下载不同类型计算机格式的文件而不向用户显示?