1024programmer Java How to remove listener for DocumentSnapshot event (GoogleCloudFireStore)

How to remove listener for DocumentSnapshot event (GoogleCloudFireStore)

I am new to Google Cloud FireStore.

The Document object has an onSnapshot function call, which is used to attach a listener for the DocumentSnapshot event.

Is there a function to delete this listener (such as offSnapshot)? If not, how can I implement this?

1> Scarygami..:

For web and node.js SDK, calling onSnapshot returns a function, You need to save it in a variable and call it when you want to remove the listener.

var unsubscribe = db.collection("cities").onSnapshot(function (querySnaphot) {
   // do something with the data.

 // Stop listening to changes

Other SDKs provide similar functionality.

For reference, see https://firebase.google.com/docs/firestore/query-data/listen#detach_a_listener.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/770309

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us


Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top