没有连接时,不会调用插入/删除文档回调上的Firestore数据库 [英] Firestore database on insert/delete document callbacks not being invoked when there is no connection

查看:53
本文介绍了没有连接时,不会调用插入/删除文档回调上的Firestore数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android上使用Firestore数据库.

I am trying firestore database on Android.

这是我插入文档的代码:

This is my code that inserts a document:

public Observable<Post> createPost(final Post post){


        return Observable.create(new Observable.OnSubscribe<Post>() {
            @Override
            public void call(final Subscriber<? super Post> subscriber) {

                try{

                    DocumentReference documentReference = getCollection().document();

                    post.setId(documentReference.getId());
                    documentReference.set(post).addOnSuccessListener(new OnSuccessListener<Void>() {
                        @Override
                        public void onSuccess(Void aVoid) {

                            subscriber.onNext(post);
                            subscriber.onCompleted();

                        }
                    }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            subscriber.onError(e);
                            subscriber.onCompleted();
                        }
                    });


                }catch (Exception ex){

                    subscriber.onError(ex);

                    Log.e(LOG_TAG, ex.getMessage(), ex);

                }

            }
        });


    }

文档被插入数据库,但是onSuccess和onFailure回调均未调用.

The document gets inserted into the database but neither of the onSuccess nor the onFailure callbacks are invoked.

  1. 这个问题有时并不一致,有时一个小时后调用回调,有时3小时后等.

  1. The issue is not consistent sometimes it works, sometimes the callbacks are invoked after an hour, sometimes after 3 hours etc..

当没有互联网连接时就会发生这种情况.

This is happening when there is no internet connection.

更新2

  1. 此处报告了该问题,并已将其关闭.我不确定如何保证离线创建的数据的正确性.
  1. The issue was reported here and it is closed. I am not sure how to guarantee the correctness of data created offline.

推荐答案

我遇到了带有本机响应的问题.

I came across this with react native.

对于插入,关键是创建一个新文档.

For inserts the key is to create a new document.

示例:

const userRef = firebase.firestore()
                  .collection("users")
                  .doc();
userRef.set({name: someName});

这将离线创建文档并在您重新联机时进行同步.

This will create the document offline and sync when you come back online.

诸如此类的其他呼叫将在离线状态下工作

Further calls such as this will work offline

userRef.collection("Locations").add({location: "Austin,TX"});

这篇关于没有连接时,不会调用插入/删除文档回调上的Firestore数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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