当同时从2个客户端调用FirebaseFirestore delete()函数时,两个客户端均成功

问题描述:

在我的情况下,文档(例如C)从集合中删除,例如PQR.

In my case, a document (say C) is deleted from a collection, say PQR.

我同时在2个客户端A和B中调用以下代码.

I call the following the following piece of code in 2 clients A and B simultaneously.

 db.collection("PQR").document("C").delete().addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {

        }
    });

删除后将调用两个客户端中的 onSuccess().

The onSuccess() in both the clients is called after the delete.

这怎么可能,因为根据我的看法,只有一个客户端应该能够删除该文档,并且应该调用客户端A或客户端B的onSuccess.

How is this possible, since according to me only one of the clients should be able to delete the document and the onSuccess of either client A or client B should be called.

请帮助.

如果完成了操作的预期结果,则为操作调用 onSuccess 侦听器,对于delete()表示如果操作后不存在文档,则调用 onSuccess .呼叫是否主动删除了文档,或者该文档在呼叫之前不存在,都没有关系.

The onSuccess listener is called for an operation if the intended result of the operation was accomplished, which in the case of delete() means that onSuccess is called if the document doesn't exist after the operation. It doesn't matter for that if the call actively deleted the document, or if the document didn't exist before the call.

如果要检测特定呼叫是否删除了文档,则需要

If you want to detect if a specific call deletes the document, you'll need to use a transaction for the operation.