问题
I have the following transaction using Firestore:
mDb.runTransaction(new Transaction.Function<Void>() {
@Override
public Void apply(final Transaction transaction) throws FirebaseFirestoreException {
DocumentReference documentReference = mDb.collection("collectionOne").document("documentOne");
/*
some code
*/
transaction.update(documentReference, App.getResourses().getString(R.string.field_one), FieldValue.increment(1));
transaction.update(documentReference, App.getResourses().getString(R.string.field_two), FieldValue.increment(1));
return null;
}
}).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d("Debugging", "Transaction correctly executed.");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w("Debugging", "Transaction failure.", e);
}
});
My question is: when updating, for example, two fields of the same document within the same transaction, will such a transaction yield to one or two documents reads?
回答1:
when updating, for example, two fields of the same document within the same transaction, will such a transaction yield to one or two documents reads?
Doesn't matter how many fields you change in a document in one operation, you'll always be charged with one write operation. If you make the writes, one after the other, you'll be charged with two write operations.
来源:https://stackoverflow.com/questions/56346671/pricing-when-updating-more-than-one-field-of-the-same-document-within-a-firestor