pulyaevskiy / firebase-admin-interop

Firebase Admin Interop Library for Dart
BSD 3-Clause "New" or "Revised" License
80 stars 37 forks source link

firestore DocumentReference.update does not support Preconditions #48

Open whesse opened 5 years ago

whesse commented 5 years ago

The node.js API for DocumentReference.update allows an optional second argument, Preconditions. This is missing from the firebase-admin-interop implementation.

The Dart package implements the Precondition object, documents it as used in Transaction, DocumentReference, and WriteBatch, but it is only available in the Transaction.update call, not the other two.

The firestore_binding js DocumentReference collection seems to declare the JS call with the correct arguments: external Promise update(UpdateData data, [Precondition precondition]); So it seems like the Dart DocumentReference implementation could just call nativeInstance.update(docData, _getNativePrecondition(lastUpdateTime)) in the case that an optional Timestamp is passed to it, as is the case with Transaction.

I would like to update documents from DocumentReference, but be sure that I am not overwriting other's changes.

whesse commented 5 years ago

It turns out that for my use case, Transaction is the correct thing to use. Since I am reading a document, and updating it based on the read values, and don't want other writes inbetween, Transaction gives me this guarantee, and automatically retries when there is a conflict, so it has all I need built in to it. So this bug is not a blocker for me.