事务中更新同一文档的多个字段时的定价

事务中更新同一文档的多个字段时的定价

本文介绍了在 Firestore 事务中更新同一文档的多个字段时的定价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Firestore 进行了以下交易:

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?

推荐答案

无论您在一次操作中更改了文档中的多少个字段,您始终需要进行一次写入操作.如果您一个接一个地进行写入,您将需要承担两次写入操作.

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.

这篇关于在 Firestore 事务中更新同一文档的多个字段时的定价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 19:19