Pricing when updating more than one field of the same document within a Firestore transaction

杀马特。学长 韩版系。学妹 提交于 2021-02-05 08:11:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!