Google Cloud Functions错误:“无法解析Firestore值中的类型”

时间:2017-12-18 23:58:08

标签: javascript firebase google-cloud-functions google-cloud-firestore

在React应用程序中使用Firestore,我使用Google Cloud Functions测试以获取文档字段,然后使用该字段在Firestore中创建新字段。我有一天工作,现在不是。

这是我在Google云端功能日志中出现的错误:

  

错误:无法从Firestore值解码类型:{“stringValue”:“sox”}   在DocumentSnapshot._decodeValue

以下是我使用的代码。它与此处的代码非常相似:https://firebase.google.com/docs/firestore/extend-with-functions#writing_data

exports.createShowDoubleName = functions.firestore
  .document('shows/{showId}')
  .onUpdate((event) => {
    const data = event.data.data();
    const previousData = event.data.previous.data();
    if (data.name == previousData.name) return;
    var name = data.name;
    var newname = name+"_"+name
     return event.data.ref.set({
        newname: newname
      }, {merge: true});
});

4 个答案:

答案 0 :(得分:2)

运行SELECT * FROM table1 WHERE tagset = (SELECT SUM(tags) FROM table4 WHERE id3 IN ('xx', 'yy')); // Using '=' will only return matches with tag xx and yy exactly SELECT * FROM table1 WHERE tagset & (SELECT SUM(tags) FROM table4 WHERE id3 IN ('xx')); // Using '&' will return all matches with xx 的最新版本(0.7.4)时,我无法重现错误。

您必须运行旧版本,因为当前版本的firebase-functions需要触发器函数才能返回Promise或值。对于当前版本,此语句会产生错误:

firebase-functions

并且必须更改为:

if (data.name == previousData.name) return;

建议您通过在项目的if (data.name == previousData.name) return null; 文件夹中运行此命令来升级firebase-functions

functions

答案 1 :(得分:1)

我有同样的问题和同样的错误。在升级了firebase-functions和firebase-admin(npm install firebase-functions @ latest --save)和(npm install firebase-admin @ latest --save)之后,它解决了这个问题。进一步研究日志问题似乎是旧版本的firebase-admin。我现在正在运行管理员版本5.5.1并运行0.7.4版本。

答案 2 :(得分:1)

绝对只需要更新一些东西。

打开终端导航到功能文件夹并从那里运行此更新:

npm install firebase-functions@latest firebase-admin@latest --save

答案 3 :(得分:1)

firebase-functions SDK version 0.7.5应该可以解决问题。它现在强制对firebase-admin 5.5.0的对等依赖。得到它:

npm install firebase-functions@0.7.5