【问题标题】:What is the difference between Function.database and Firebase.database? When to use one over the other?Function.database 和 Firebase.database 有什么区别?什么时候使用一个而不是另一个?
【发布时间】:2019-11-30 10:19:53
【问题描述】:

我从 firebase 开始,并且一直在阅读大量示例代码。我注意到的一件事是,一些示例在获取参考数据时使用了 functions.database,而另一些则使用了 firebase.database。

这例如使用functions.database https://firebase.google.com/docs/functions/database-events

这个使用 firebase.database https://firebase.google.com/docs/database/web/read-and-write

使用其中一个有什么功能优势吗?

谢谢

【问题讨论】:

    标签: firebase firebase-realtime-database


    【解决方案1】:

    它们用于两种不同的上下文:

    1. functions.database 在您注册/创建一个触发来自特定 Firebase 实时数据库实例的事件的 Cloud Function 时使用。因此,它用于在 Cloud Function 平台上在后端执行的代码中。
    2. 相反,firebase.database() 用于前端,与客户端 JavaScript SDK 一起使用。它用于获取firebase.database.Reference 的实例,以便从/向 Firebase 实时数据库读取/写入数据。

    所以这一切都取决于你计划在哪里执行你的代码。

    【讨论】:

    • 非常感谢。我知道现在该使用哪一个了。
    猜你喜欢
    • 1970-01-01
    • 2011-10-01
    • 2010-10-28
    • 2020-06-08
    • 2011-01-11
    • 1970-01-01
    • 2018-06-04
    • 2017-01-23
    • 2015-04-23
    相关资源
    最近更新 更多