[英]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具有类型为Reference的ref属性,该属性指向数据的位置。 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.