Home > Enterprise >  how does snapshot with (Events for metadata changes) differs than normal snapshot in cloud firestore
how does snapshot with (Events for metadata changes) differs than normal snapshot in cloud firestore

Time:03-21

What is the main difference between using { includeMetadataChanges: true } in snapshot function and not using it at all, as I understood from docs it kind of more sensitive to change ?

import { doc, onSnapshot } from "firebase/firestore";

const unsub = onSnapshot(
  doc(db, "cities", "SF"), 
  { includeMetadataChanges: true }, 
  (doc) => {
    // ...
  });

CodePudding user response:

When you listen for values with includeMetadataChanges: true, your callback also gets invoked when only the metadata of a snapshot has changed. Specifically this may happen when the client has verified that there were no changes on the server (so fromCache becomes true) or when local writes have been committed on the server (and so hasPendingWrites becomes false).

Without the flag, you'd not be notified of those changes, as they're not commonly shown in the UI of the app (although they definitely can be).

  • Related