Как правильно переписать код с Firebase в cloud Firestore?

Я написал для подключения к Firebase, и теперь я хочу перенести все в cloud Firestore, 1 первый метод написан, чтобы получить «Comment» из Firebase.

private void iniRvComment() {
        RvComment.setLayoutManager(new LinearLayoutManager(this));
        DatabaseReference commentRef = firebaseDatabase.getReference(COMMENT_KEY).child(postKey);
        commentRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                listComment = new ArrayList<>();
                for(DataSnapshot snapshot: dataSnapshot.getChildren()){
                    Comment comment = snapshot.getValue(Comment.class);
                    listComment.add(comment);
                }
                commentAdapter = new CommentAdapter(getApplicationContext(), listComment);
                RvComment.setAdapter(commentAdapter);
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });
    }

2 метод, как переписать этот код, чтобы получить из «Comment» из cloud firestore. То что я написал ниже, не работает

private void iniRvComment() {
        RwComment.setLayoutManager(new LinearLayoutManager(this));
        DocumentReference docRef = firestore.collection("Comment").document(postKey);
        docRef.collection("Comment").addSnapshotListener(new EventListener<QuerySnapshot>() {
            @Override
            public void onEvent(@Nullable QuerySnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
                if (documentSnapshot != null && !documentSnapshot.getDocuments().isEmpty()) {
                    listComment = new ArrayList<>();
                    List<DocumentSnapshot> documents = documentSnapshot.getDocuments();
                    for (DocumentSnapshot value : documents) {

                        Comment comment = value.toObject(Comment.class);
                        listComment.add(comment);
                    }
                    commentAdapter = new CommentAdapter(getApplicationContext(), listComment);
                    RwComment.setAdapter(commentAdapter);
                }
            }
        });
    }

введите сюда описание изображения


Ответы (0 шт):