Unsubscribe from a Firestore watch listener

Unsubscribe from a Firestore watch listener

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

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