【问题标题】:Value for argument "documentPath" is not a valid resource path. Firebase Cloud Functions参数“documentPath”的值不是有效的资源路径。 Firebase 云函数
【发布时间】:2020-07-29 10:24:57
【问题描述】:

我有一个 Firestore 触发器。但是我遇到了错误

sendChatPushNotification
Error: Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string.
    at Object.validateResourcePath (/workspace/node_modules/@google-cloud/firestore/build/src/path.js:403:15)
    at CollectionReference.doc (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:1988:20)
    at exports.sendChatPushNotification.functions.firestore.document.onWrite (/workspace/index.js:38:8)
    at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:132:23)
    at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:198:28)
    at process._tickCallback (internal/process/next_tick.js:68:7) 

更新依赖项后出现此错误。现在我的 package.json

  "dependencies": {
    "firebase-admin": "9.0.0",
    "firebase-functions": "^3.8.0"
  },
  "devDependencies": {
    "eslint": "^7.5.0",
    "eslint-plugin-promise": "^4.2.1"
  },
  "engines": {
    "node": "10"
  },

这是我的云功能

exports.sendChatPushNotification = functions.firestore
  .document("channels/{some_channel_document}/thread/{some_thread_document}")
  .onWrite((change, context) => {
    const data = change.after.data();
    const senderFirstName = data.senderFirstName;
    const content = data.content;
    const recipientID = data.recipientID;
    const url = data.url;

    let payload = {};

    if (url) {
      payload = {
        notification: {
          title: "Yeni Mesaj",
          body: `${senderFirstName} bir resim gönderdi`
        }
      };
    } else {
      payload = {
        notification: {
          title: "Yeni Mesaj",
          body: `${senderFirstName}: ${content}`
        }
      };
    }

    let pushToken = "";
    return firestore
      .collection("users")
      .doc(recipientID)
      .get()
      .then(doc => {
        pushToken = doc.data().pushToken;
        return admin.messaging().sendToDevice(pushToken, payload);
      });
  });

我尝试了类似 ${some_channel_document} 的不同路径,但问题没有解决

感谢您的帮助...

【问题讨论】:

  • 错误告诉您,您分配的文档路径正在获取空对象。尝试打印文档路径,看看文档路径中有什么。
  • 能否分享一下你的云函数的完整代码?
  • @RenaudTarnec 我添加了
  • 我认为问题不在于您触发云功能的路径(即exports.sendChatPushNotification = functions.firestore .document("channels/{some_channel_document}/thread/{some_thread_document}") .onWrite((change, context) => {}) 是正确的)。你能检查recipientID的值吗?
  • @RenaudTarnec 是的,你是对的。我在你的帮助下解决了这个问题。非常感谢!

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


【解决方案1】:

我认为问题不在于您触发云功能的路径(即exports.sendChatPushNotification = functions.firestore .document("channels/{some_channel_document}/thread/{some_thread_document}") .onWrite((change, context) => {}) 是正确的)。

问题很可能来自您在代码中声明 DocumentReference 的其他地方,即:

firestore.collection("users").doc(recipientID)...

你应该检查recipientID的值。

【讨论】:

    猜你喜欢
    • 2020-09-17
    • 2020-10-24
    • 2020-11-19
    • 2020-12-21
    • 2017-11-13
    • 2018-09-03
    • 2017-11-15
    • 1970-01-01
    • 2012-10-25
    相关资源
    最近更新 更多