简体   繁体   中英

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. One thing I notice is that some sample uses functions.database and some uses firebase.database when getting reference data.

This for example uses 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

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. So it is used in code that is executed in the back-end , on the Cloud Function platform.
  2. On the opposite, firebase.database() is used in the front-end , with the 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.

So it all depends on where you plan to execute your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM