ref

This method behaves very similarly to the method of the same name in the client and Admin Firebase SDKs. Any change to the Database that affects the data at or below the provided path will fire an event in Cloud Functions.

There are three important differences between listening to a Realtime Database event in Cloud Functions and using the Realtime Database in the client and Admin SDKs:

Cloud Functions allows wildcards in the path name. Any path component in curly brackets ({}) is a wildcard that matches all strings. The value that matched a certain invocation of a Cloud Function
is returned as part of the event.params object. For example,
ref("messages/{messageId}") matches changes at /messages/message1 or
/messages/message2, resulting in event.params.messageId being set to
"message1" or "message2", respectively.

Cloud Functions do not fire an event for data that already existed before the Cloud Function was deployed.

Cloud Function events have access to more information, including a snapshot of the previous event data and information about the user who triggered the Cloud Function.