简体   繁体   English

Function.database 和 Firebase.database 有什么区别? 什么时候使用一个而不是另一个?

[英]What is the difference between Function.database and Firebase.database? When to use one over the other?

I am starting off with firebase and I have been reading significant amount of sample codes.我从 firebase 开始,并且一直在阅读大量示例代码。 One thing I notice is that some sample uses functions.database and some uses firebase.database when getting reference data.我注意到的一件事是,一些示例在获取参考数据时使用 functions.database,而一些示例使用 firebase.database。

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

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

Is there any functional advantage using one over the other?使用一个比另一个有什么功能优势吗?

Thanks谢谢

They are used in two different contexts:它们用于两种不同的情况:

  1. functions.database is used when you register/create a Cloud Function that triggers on events from a specific Firebase Realtime Database instance. functions.database在您注册/创建触发来自特定 Firebase 实时数据库实例的事件的Cloud Function时使用。 So it is used in code that is executed in the back-end , on the Cloud Function platform.所以它被用在后端执行的代码中,在 Cloud Function 平台上。
  2. On the opposite, firebase.database() is used in the front-end , with the Client JavaScript SDK.相反,前端使用firebase.database() ,配合 Client JavaScript SDK。 It is used to get an instance of firebase.database.Reference , in order to read/write data from/to the Firebase Realtime Database.它用于获取firebase.database.Reference的实例,以便从/向 Firebase 实时数据库读取/写入数据。

So it all depends on where you plan to execute your code.所以这完全取决于您计划在哪里执行代码。

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

相关问题 当我使用 firebase.database().goOnline(); 我得到一个错误 - when i use firebase.database().goOnline(); I get an error firebase.database 不是 function 为什么我在反应本机应用程序中收到此错误? - firebase.database is not a function why I am getting this error in react native app? Cloud Firestore 和 Firebase 实时数据库有什么区别? - What's the difference between Cloud Firestore and the Firebase Realtime Database? firebase.database(app) arg 需要一个 FirebaseApp 实例或未定义 - firebase.database(app) arg expects a FirebaseApp instance or undefined 实时数据库 Firebase 与 Firebase 云 function 的事件 child_added 之间的区别 - Difference between event child_added of Realtime Database Firebase vs Firebase Cloud function aws数据库服务与数据库引擎有什么区别 - what is difference between aws database service vs database engine 如何使用 on() firebase 数据库方法返回值给调用 function? - how to use on() firebase database method to return value to the calling function? 访问子 firebase 数据库时的“app”属性是什么(javascript) - What is `app` property when access child firebase database (javascript) 每个客户一个 firebase 数据库 - One firebase database for every customer 在 firebase 数据库上执行注册 function 时不断崩溃 - Constantly crashes when performing registration function on firebase database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM