Unsubscribe from a Firestore watch listener

Stay organized with collections Save and categorize content based on your preferences.

Unsubscribe from a Firestore watch listener

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

Go

// Сontext with timeout stops listening to changes.
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()

Java

Query query = db.collection("cities");
ListenerRegistration registration =
    query.addSnapshotListener(
        new EventListener<QuerySnapshot>() {
          // ...
        });

// ...

// Stop listening to changes
registration.remove();

Node.js

const unsub = db.collection('cities').onSnapshot(() => {
});

// ...

// Stop listening for changes
unsub();

Python

# Terminate watch on a document
doc_watch.unsubscribe()

Ruby

listener.stop

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.