Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Firestore:查询集合中的所有文档_Android_Firebase Authentication_Google Cloud Firestore - Fatal编程技术网

Android Firestore:查询集合中的所有文档

Android Firestore:查询集合中的所有文档,android,firebase-authentication,google-cloud-firestore,Android,Firebase Authentication,Google Cloud Firestore,我的Firestore结构如下所示: -(coll)users -(doc)uniqueID name email (coll)clients -(doc)uniqueID clientName clientEmail 我正在努力实现以下目标: 用户通过FirebaseUI身份验证流登录 如果用户(从身份验证中恢复的uid)在firestore db中不存在,我将创建一个以其uid命名的文档 获得uid

我的Firestore结构如下所示:

-(coll)users
    -(doc)uniqueID  
    name
    email  
    (coll)clients
        -(doc)uniqueID
        clientName
        clientEmail  
我正在努力实现以下目标:

  • 用户通过FirebaseUI身份验证流登录
  • 如果用户(从身份验证中恢复的uid)在firestore db中不存在,我将创建一个以其uid命名的文档
  • 获得uid后,我运行一个查询来加载客户端集合,以便使用RecyclerView将它们显示到列表中(如果集合为空,则用户尚未创建任何客户端,我将显示一个空列表屏幕)
  • 我尝试按照以下代码进行查询:

    即使clients集合中存在一些以unique uid命名的文档,我也会得到这个结果


    谢谢你能给我的任何线索!:)

    运行第一条语句时,错误消息指示
    mUid
    null
    。这很可能意味着您在用户登录之前运行此代码

    确保仅在用户登录后调用此代码,例如从
    AuthStateListener.onAuthStateChanged()

    FirebaseAuth.getInstance().addAuthStateListener(新的AuthStateListener()){
    AuthStateChanged上的公共无效(FirebaseAuth auth){
    FirebaseUser=firebaseAuth.getCurrentUser();
    如果(用户!=null){
    clientsCollection=db.collection(FIRESTORE\u collection\u用户)
    .document(user.getUid())
    .收集(FIRESTORE\u收集\u客户);
    客户端集合
    .get()
    .addOnCompleteListener(新的OnCompleteListener(){
    @凌驾
    未完成的公共void(@NonNull任务){
    if(task.issusccessful()){
    对于(DocumentSnapshot文档:task.getResult()){
    Log.d(Log_标记,document.getId()+“=>”+document.getData());
    }
    }否则{
    d(Log_标记,“获取文档时出错:”,task.getException());
    }
    }
    }
    }
    })
    
        clientsCollection = db.collection(FIRESTORE_COLLECTION_USERS)
                .document(mUid)
                .collection(FIRESTORE_COLLECTION_CLIENTS);
    
        clientsCollection
                .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                        if (task.isSuccessful()){
                            for (DocumentSnapshot document: task.getResult()){
                                Log.d(LOG_TAG, document.getId() + " => " + document.getData());
                            }
                        } else {
                            Log.d(LOG_TAG, "error getting documents: ", task.getException());
                        }
                    }
                });
    
    java.lang.NullPointerException: Provided document path must not be null.
    
    FirebaseAuth.getInstance().addAuthStateListener(new AuthStateListener() {
        public void onAuthStateChanged(FirebaseAuth auth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                clientsCollection = db.collection(FIRESTORE_COLLECTION_USERS)
                        .document(user.getUid())
                        .collection(FIRESTORE_COLLECTION_CLIENTS);
    
                clientsCollection
                        .get()
                        .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                            @Override
                            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                                if (task.isSuccessful()){
                                    for (DocumentSnapshot document: task.getResult()){
                                        Log.d(LOG_TAG, document.getId() + " => " + document.getData());
                                    }
                                } else {
                                    Log.d(LOG_TAG, "error getting documents: ", task.getException());
                                }
                            }
            }
        }
    })