gpt4 book ai didi

javascript - 如何修复参数 "documentPath"的值不是有效的资源路径?

转载 作者:行者123 更新时间:2023-12-04 10:15:18 27 4
gpt4 key购买 nike

我正在尝试触发一个函数,该函数将在子集合上访问 token ,在不指定的情况下浏览文档。在 dart 中,我可以使用 documentId,我可以使用 javascript 类似的东西吗?尝试了以下操作,但它返回给我:

Value for argument "documentPath" is not a valid resource path



关于如何修复它的任何灯?在此先感谢您的帮助!
const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);

var msgData;
var documentId = admin.firestore.FieldPath.documentId();



exports.chatTrigger = functions.firestore.document(
'chat/{chatId}/users/{usersId}/messages/{messagesId}')
.onCreate((snapshot, context) => {
msgData = snapshot.data();

return
admin.firestore().collection('chat').doc(documentId)
.collection(documentId).doc(documentId)
.collection('messages').get().then((snapshots) => {
var tokens = [];
if (snapshots.empty) {
console.log('No Devices');
return false;


} else {
for (var token of snapshots.docs) {
tokens.push(token.data().token);
}

var payload = {
"notification": {
"title": msgData.name,
"body": msgData.title,
"sound": "default"
},
"data": {
"sendername": msgData.name,
"message": msgData.title,
}
}

return admin.messaging().sendToDevice(tokens, payload).then((response) => {
console.log('Pushed them all');
}).catch((err) => {
console.log(err);
})
}

})
})

我相信我的 documentId 在 'admin.firestore().collection('chat')
.doc(documentId).collection(documentId).doc(documentId).collection('messages').'没有按照我的预期返回给我。

最佳答案

Update Sub-collections on CloudFunctions 上找到了我的答案,只需要指定:

const chatId = context.params.chatId;
const usersId = context.params.usersId;

谢谢@Frank van Puffelen!

关于javascript - 如何修复参数 "documentPath"的值不是有效的资源路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61090288/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com