Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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) => {
    // ...
  });
like image 764
Richardson Avatar asked Oct 27 '25 06:10

Richardson


1 Answers

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).

like image 180
Frank van Puffelen Avatar answered Oct 29 '25 20:10

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!