【问题标题】:Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string参数“documentPath”的值不是有效的资源路径。路径必须是非空字符串
【发布时间】:2020-09-17 19:03:20
【问题描述】:

我想写一个云函数来监听是否在users的某个文档的following子集合中创建了一个新文档。但是,之前创建的用户文档可能没有following 子集合。

换句话说,我想要一个响应db.collection(“users”).doc(“doc_id1”).collection(“following”).doc(“doc_id2”).set(new_document) 的云 ,并且我已经将云函数写成了

exports.create_friend_request_onCreate = functions.firestore
  .document("users/{user_id}/{following}/{following_id}")
  .onCreate(f2);

f2 的实现写在其他文件中

exports.f2 = async function(snapshot) {
 //some code
}

但是在子集合中创建文档时,我收到以下错误

Error: Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string.

谁能给我解释一下这里出了什么问题?

【问题讨论】:

    标签: node.js firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    改变这个:

      .document("users/{user_id}/{following}/{following_id}")
    

    进入这个:

      .document("users/{user_id}/following/{following_id}")
    

    collection 不应该有 {wildcard}

    【讨论】:

    • 进行更改和部署后我仍然收到错误
    【解决方案2】:

    正确的路径应该是'users/{user_id}/following/{following_id}',显然双引号不能作为路径。

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,这个问题的原因是文档路径必须是一个字符串。 collection("questions").doc(21) 是错误的。 collection("questions").doc("21") 工作。

      -你必须确保变量是字符串 .你可以使用"users/{String(user_id)}/{following}/{String(following_id)}"

      【讨论】:

        猜你喜欢
        • 2020-10-24
        • 1970-01-01
        • 2017-04-23
        • 2021-08-18
        • 2017-04-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多