Javascript “如何确定参数的值”;“文档路径”;不是有效的资源路径吗?
我试图触发一个函数,该函数将在子集合上访问令牌,遍历文档而不指定它。在dart中,我可以使用documentId,我可以使用类似于javascript的东西吗?尝试了以下操作,但它返回我: 参数“documentPath”的值不是有效的资源路径 有关于如何修理它的指示灯吗?提前感谢您的帮助Javascript “如何确定参数的值”;“文档路径”;不是有效的资源路径吗?,javascript,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Firebase,Google Cloud Firestore,Google Cloud Functions,我试图触发一个函数,该函数将在子集合上访问令牌,遍历文档而不指定它。在dart中,我可以使用documentId,我可以使用类似于javascript的东西吗?尝试了以下操作,但它返回我: 参数“documentPath”的值不是有效的资源路径 有关于如何修理它的指示灯吗?提前感谢您的帮助 const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initial
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);
})
}
})
})
我相信我在“admin.firestore().collection('chat')上的文档ID
.doc(documentId).collection(documentId).doc(documentId).collection('messages').”没有返回我所期望的结果。在上找到我的答案,只需要指定:
const chatId = context.params.chatId;
const usersId = context.params.usersId;
谢谢@Frank van Puffelen 请编辑该问题,使其更具体地说明您正在执行的导致错误的操作、它位于哪一行以及到目前为止您为调试它所做的工作。你现在掌握的信息还不够。理想情况下,您的问题包含足够的信息,以便任何人都可以自己再现问题。