Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firebase函数未为Cloud Firestore启动_Javascript_Firebase_Google Cloud Firestore_Google Cloud Functions - Fatal编程技术网

Javascript Firebase函数未为Cloud Firestore启动

Javascript Firebase函数未为Cloud Firestore启动,javascript,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Firebase,Google Cloud Firestore,Google Cloud Functions,我根本看不出我错在哪里。我的云Firestore位于“europe-west3”上,功能部署在“europe-west1”上(文档告诉我这是离west3最近的位置) 结构是这样的:我有一堆“票”,每个票都可以有一个子集合,名为“评论”。因此,控制台如下所示: functions.region('europe-west1').firestore.document('...') 上载成功: 函数代码取自官方代码示例 这就是我的代码的样子: const functions=require('f

我根本看不出我错在哪里。我的云Firestore位于“europe-west3”上,功能部署在“europe-west1”上(文档告诉我这是离west3最近的位置)

结构是这样的:我有一堆“票”,每个票都可以有一个子集合,名为“评论”。因此,控制台如下所示:

functions.region('europe-west1').firestore.document('...')

上载成功:

函数代码取自官方代码示例

这就是我的代码的样子:

const functions=require('firebase-functions');
const admin=require('firebase-admin');
admin.initializeApp();
exports.countComments=functions.region('europe-west1').database.ref('/tickets/{ticketId}/comments/{commentsid}'))
.onWrite(
异步(更改)=>{
const ticketsRef=change.after.ref.parent;
const countRef=ticketsRef.parent.child('comments_count');
让我们增加;
if(change.after.exists()&&!change.before.exists()){
增量=1;
}如果(!change.after.exists()&&change.before.exists()){
增量=-1;
}否则{
返回null;
}
等待计数参考事务((当前)=>{
返回(当前| | 0)+增量;
});
console.log(“计数器更新”);
返回null;
});
exports.recontcomments=functions.region('europe-west1').database.ref('/tickets/{ticketId}/comments\u count'))
onDelete先生(
异步(快照)=>{
常数计数器参考=snap.ref;
const collectionRef=counterRef.parent.child('comments');
const commentsData=await collectionRef.once('value');
return wait counterRef.set(commentsData.numChildren());
}
)
现在的问题是,这些函数根本无法启动。我在日志中没有看到任何东西,不管我是通过我的客户端(一个flatter应用程序)推动更改,还是直接在Firebase控制台中更改

在我绝望的时候,我也试着简单地听“/tickets”,因为在这条路径下的任何变化都应该触发——但什么都没有

所以。我忽略的最明显的事情是什么?而且,是的,我看了其他的问题/答案,但没有任何东西跳到我身上

编辑:

这将是正确的版本,可能不是最佳的

exports.countComments=functions.region('europe-west1').firestore.document('/tickets/{ticketId}/comments/{commentsId}'))
.onWrite(
异步(更改、上下文)=>{
const ticketId=context.params.ticketId;
const ticketRef=admin.firestore().collection('tickets').doc(ticketId);
让我们增加;
if(change.after.exists&!change.before.exists){
增量=1;
}如果(!change.after.exists&&change.before.exists)存在,则为else{
增量=-1;
}否则{
返回null;
}
return transaction=admin.firestore().runTransaction(t=>{
返回t.get(ticketRef)
。然后(doc=>{
让计数=(doc.data().comments_count | | 0)+增量;
t、 更新(ticketRef,{comments\u count:count});
});
})。然后(res=>{
console.log(“计数器更新”);
}).catch(错误=>{
log('Transaction error:',err);
});
});

您的数据库是Cloud Firestore,但您已经编写了一个实时数据库触发器。它们是两个完全不同的数据库。请按照文档中的说明进行操作

您的函数将如下开始:

functions.region('europe-west1').firestore.document('...')

注意“firestore”而不是“database”。

您的数据库是Cloud firestore,但您已经编写了一个实时数据库触发器。它们是两个完全不同的数据库。请按照文档中的说明进行操作

您的函数将如下开始:

functions.region('europe-west1').firestore.document('...')

请注意“firestore”而不是“database”。

谢谢-确实是这样。我已经在上面的评论中添加了我的工作代码——数据库和firestore类似,但并不完全相同。可能还有一些德普在那里。谢谢你-确实是这样。我已经在上面的评论中添加了我的工作代码——数据库和firestore类似,但并不完全相同。那里可能还有一些毒品。