当同时从2个客户端调用FirebaseFirestore delete()函数时,两个客户端均成功 [英] FirebaseFirestore delete() function when called from 2 clients at the same time gives success in both clients

查看:39
本文介绍了当同时从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.

这篇关于当同时从2个客户端调用FirebaseFirestore delete()函数时,两个客户端均成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆