javascript - 查找由外部程序引起的当前 firebase 修改的路径
问题描述
我将 Firebase(实时数据库)与应用程序一起使用,并且在某些时候数据库的值被应用程序修改。为了捕捉这个修改,我添加了一个监听器作为 Firebase 函数。代码如下所示:
exports.chooseWordsGeneration =
functions.database.ref("roomsTest").onWrite((change, context) => {
// Get the path of the modification in the database
});
与数据库一起
因此,例如,如果应用程序修改了 test2 的值,我希望能够捕获整个路径,即“34/test2”。换句话说,我想知道哪个房间被修改了。我尝试使用change
作为参数给出的变量,onWrite
但我不是很成功。谢谢你的帮助。
解决方案
如果您想轻松“捕获整个路径,因此'34 / test2'”您必须监听 的子子节点roomsTest
,如下所示:
exports.chooseWordsGeneration = functions.database
.ref('roomsTest/{roomId}/{testId}')
.onWrite((change, context) => {
console.log(context.params.roomId + '/' + context.params.testId);
//....
return false; //to adapt
});
请注意,这change.after.val()
将为您提供testId
节点的值。
推荐阅读
- python - 标签数量不匹配?
- python - 如何在Ddjango中将查询集作为单个项目传递?
- splunk - 如何编写 splunk 查询以确保搜索正常工作?
- sql-server - 查询从 Table2 中获取 Supervisor,同时显示 Table1 中的信息
- javascript - JS 事件在 woocommerce 购物车页面上无法正常工作
- flutter - 如何在没有 MaterialPageRoute 的情况下传递参数函数 setState?
- java - Mockito、verify 和 HashMap:参数不同
- mysql - 试图重新排列mysql中的数据
- ms-access - 格式化 MS-Access 图表中的轴标签
- python - 通过 python 在 Azure DevOps 中创建工作项