How do I do something like a 'child-added' event in Firebase Cloud functions?
我需要使用 Cloud Functions 从 Firebase 实时数据库中获取新推送的子路径 (/foo)。
--newpushKey
- eeee
- ffff
--pushKey1
- cccc
- dddd
--pushkey2
- aaaa
- bbbb
我只需要新添加的数据,即,
- eeee
- ffff
我浏览了 https://firebase.google.com/docs/functions/database-events。如何仅从
或者,我是否应该使用 Admin SDK 来查询
或者,使用 Set 对
您将希望将
You can specify a path component as a wildcard by surrounding it with
curly brackets;
您需要在数据库引用中使用通配符路径,如下所示:
1 2 3 4 5 6 | exports.checkForNew = functions.database.ref('foo/{createdID}').onCreate((created_child, context) => { //context.params.createdID to reference the ID of the created object in the database under 'foo' //created_child.val() to reference any field values of the created objcet }); |
你在正确的Rails上,你甚至自己找到了相关的文档......在那个页面上,看看最后一个例子,我已经采取了那个例子并对其进行了一些编辑以制作对你来说更清楚:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | Notice this parameter? This function will only fire on the new data-node itself, not on the parent node... \\/ \\/ exports.makeUppercase = functions.database.ref('/messages/{pushId}') .onCreate( (change, context) => { // Since the function will only fire on the newly created node itself // the data that is 'after' the event will be your new data. // You can access the new data by calling: change.after.val() // From here you can do whatever actions you want with that data. // You can access the {pushId} parameter with: context.params.pushId }); |