javascript - 简单的云功能复制文档时出错
问题描述
我正在创建我的第一个云函数,它只是在创建journal
子集合activites
后将子集合中的文档复制到子集合中。我希望复制的文档具有相同的postId
. 功能日志显示
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:406:15)
at CollectionReference.doc (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:1982:20)
at exports.onCreateJournal.functions.firestore.document.onCreate (/workspace/index.js:21:8)
at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:134: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:6
这是云功能
exports.onCreateJournal = functions.firestore
.document("/users/{userId}/journal/{docID}")
.onCreate(async (snapshot, context) => {
const data = snapshot.data();
const userId = context.params.userId;
const postId = context.params.postId;
admin
.firestore()
.collection("users")
.doc(userId)
.collection("activities")
.doc(postId)
.set(data);
});
或者我应该用 Firestore 模拟器调试这个?
解决方案
错误信息:
错误:参数“documentPath”的值不是有效的资源路径。路径必须是非空字符串。
建议您将空字符串或其他一些无效值(例如未定义)传递给您对doc()
. 我的猜测是第二个。
Your wildcard path has "docID" in it, but you are trying to access it with a different name "postId". You will need to use the same name for both. Perhaps you meant to use a wildcard like this:
exports.onCreateJournal = functions.firestore
.document("/users/{userId}/journal/{postId}")
Notice that I replaced "docID" with "postId" to match your code.
推荐阅读
- css - ReactJS - 导入组件会破坏 webpack
- android - java.lang.NullPointerException:com.bumptech.glide.util 中的参数不能为空
- php - Wordpress 入站电子邮件操作
- android - getContext() 返回 Null
- c# - 即使在实现 IRequiresSessionState 之后,HttpContext.Current 仍为 null
- sql-server - SQL / TSQL 根据子查询列中的所有值更新值
- java - Gradle 任务不显示 Java 堆栈跟踪
- sharepoint - Sharepoint:AADSTS70000:身份验证失败。委托 blob 授权格式不正确
- azure-devops - VSTS 目标和目的
- jenkins - Groovy - 詹金斯管道 -