简体   繁体   English

如何在云端功能中查询Firebase数据库?

[英]How do I query a firebase database inside a cloud function?

When a cloud function is triggered based on a specific parent node, how would I be able to query a different parent node within the cloud function, and then update the initial record (that triggered the cloud function) with the queried information? 当基于特定父节点触发云功能时,我如何能够查询云功能内的另一个父节点,然后使用查询的信息更新初始记录(触发了云功能)? Thanks so much! 非常感谢!

When a database function is triggered, it's delivered a DataSnapshot of the data (or was previously, if it was a change). 触发数据库功能时,它会传递数据的DataSnapshot (或者以前是,如果已更改)。 DataSnapshot has a ref property of type Reference that points to the location of the data. DataSnapshot具有类型为Referenceref属性,该属性指向数据的位置。 You can use that Reference to build other references by using its parent and root properties, or its child() method: 您可以使用该引用通过parent属性和root属性或其child()方法来构建其他引用:

const root = snapshot.ref.root     // the root of your database
const users = root.child('users')  // the child node under root

You can also use the Admin SDK to build references to other locations, but using your existing ref is more efficient. 您也可以使用Admin SDK来建立对其他位置的引用,但是使用现有的引用效率更高。 That ref is already backed by an initialized Admin SDK instance. 该引用已由初始化的Admin SDK实例支持。

To learn how to use a reference, read the documentation on reading and writing data. 要了解如何使用参考,请阅读文档读取写入数据。 Prefer to use once() on a reference to read. 最好在引用上使用一次()进行读取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在云功能内部访问Firebase数据库? - How to Access Firebase Database Inside a Cloud Function? 如何模拟从 Firebase function 内部排队 Google Cloud 任务? - How do I emulate enqueuing a Google Cloud Task from inside a Firebase function? Firebase的云功能:如何为所有子项的特定子键触发数据库功能 - Cloud Functions for Firebase: How do I trigger a database function for a specific child key of all children Firebase数据库-云功能查询 - Firebase-database - Cloud function query 我如何处理 firebase 云 function api oncall 的错误? - how do i handle the error for firebase cloud function api oncall? 如何使用Firebase云功能查询数据库 - How to query database with firebase cloud functions 如何在云功能中获取firebase数据库数据? - How to fetch firebase database data in cloud function? 如何在使用 Cloud Functions 时使用 Firebase Admin SDK 更改 Firebase 实时数据库中的数据? - How do I use Firebase Admin SDK to change data in Firebase Realtime Database while using Cloud Functions? 如何从 firebase 云 function 内部获取 firebase 用户 ID - How to get firebase userID from inside a firebase cloud function 如何做云 function firebase 将数据从 Bucket 实时导入数据库 - how to do a cloud function firebase importing data from Bucket to database realtime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM