[英]Value for argument "documentPath" is not a valid resource path. Firebase Cloud Functions
I have a firestore trigger.我有一个 Firestore 触发器。 But I encountered an error
但是我遇到了一个错误
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)
I got this error after update my dependencies.更新我的依赖项后出现此错误。 Now my package.json
现在我的 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"
},
And this is my cloud function这是我的云 function
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);
});
});
I tried different path like this ${some_channel_document} but the problem is not solved我试过像这样的不同路径 ${some_channel_document} 但问题没有解决
Thanks for your help...谢谢你的帮助...
I don't think the problem is with the path on which you trigger the Cloud Function (ie exports.sendChatPushNotification = functions.firestore.document("channels/{some_channel_document}/thread/{some_thread_document}").onWrite((change, context) => {})
is correct).我认为问题不在于您触发 Cloud Function 的路径(即 exports.sendChatPushNotification
exports.sendChatPushNotification = functions.firestore.document("channels/{some_channel_document}/thread/{some_thread_document}").onWrite((change, context) => {})
是正确的)。
The problem most probably comes from the other place where you declare a DocumentReference
in your code, ie:问题很可能来自您在代码中声明
DocumentReference
的其他地方,即:
firestore.collection("users").doc(recipientID)...
You should check the value of recipientID
.您应该检查
recipientID
的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.