I think I am seeing the observable dataflow fire twice when I listen to a document that includes a FieldValue.serverTimestamp(). Is that possible / expected?
Thanks! I don't really need timestamps and was just using them to be notified (via listen) when a new document is added to a specific collection, following your example here. Is there a simpler pattern for achieving that, which behaves the same whether the new doc is added locally or remotely?
here the timestamp is a field, so if you don't need it don't write it. Are you requiring ordering as well? If you do require ordering you could use local timestamp, but thats sometimes a problem. If you need to use server timestamps, you can look at the pendingWrites meta property and filter there? https://stackoverflow.com/questions/49972173/firestore-onsnapshot-executing-twice
If you add the pendingWrites filter as an option to "listen" I would merge it.
I just added an ignorePendingWrites option on my fork and tested that it fixes this issue.
However, I suspect I am approaching my design the wrong way if these implementation subtleties are breaking it. I just want an observable cell that watches a specific collection and has the value of the newest document added. I am only use a timestamp as a means to achieve this end, since I could find any other way to query for the most recently added document.
I guess a different pattern I could use it to write two docs with the same content, once as a new document and once with a predefined name, then listen to the predefined name, i.e.
db.collection("C").add(content);
db.collection("C").doc("latest").set(content);
newest = listen(db.collection("C").doc("latest"))
Oh right, if you want just a single latest, overwrite a common document. If you need to keep the history, each update is a new doc in a collection. If you need to track the 'latest', even when using the history, issue a realtime query that is ordered by timestamp, with a limit of 1 documents. You can "listen" to a query too