I have three listeners
- Get Visible Data to all user
- Get Data Between two dates
- Get All Data
However, When any Data change user table the Listener call automatically 4-5 times.
func listenData() -> ListenerRegistration { let listener = db.collection("user") .whereField("FirstRow", isGreaterThanOrEqualTo: "FirstRow") .whereField("lastRow", isLessThanOrEqualTo: "lastRow") .addSnapshotListener { querySnapshot, error in if let error = error { print("listener error: \(error.localizedDescription)") return } if let snapshot = querySnapshot { print("Without For Each = Data") snapshot.documentChanges.forEach { diff in print("For Each = Data") } print("listen Public Rides Loop Done") } } return listener } Question: How to Listener call once time when user change the data?
Can someone please explain to me How to Listener call once time only?
Any help would be greatly appreciated.
Thanks in advance.
get()instead ofaddSnapshotListeneras shown in firebase.google.com/docs/firestore/query-data/get-dataonSnapshot. But that will always also give you the initial snapshot of the data in the database. If you don't need that for your use-case, you will either have to ignore it in your application code, or you will have to come up with a query that only returns the documents you're interested in (for example by including a timestamp in there). There is no way to tell Firebase to skip the initial payload.