Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] firebase – Unable to get all documents under root collection – Firestore Android

Posted on November 14, 2022

Solution 1 :

the 1st document under users collection which had I added by code looks italic

That means there is no actual document there. What you’ve done is create a document in a subcollection under than document ID without also creating that document. That’s not an error, but you need to be aware that it’s also not an actual document and won’t show up in queries. It’s just shown there so you can find the nested subcollection in the console.

Solution 2 :

data is empty bro thats why you got this problem.
okay listen i will share a block of code may this help you when you have data in firestore collection

 FirebaseFirestore db = FirebaseFirestore.getInstance();
        db.collection("matches")
                .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                        if (task.isSuccessful()) {

                            for (QueryDocumentSnapshot document : task.getResult()) {
                                Log.d("", document.getId() + " => " + document.getData());

                                String actualPlayers = document.get("actualPlayers").toString();
                                String city = document.get("city").toString();
                             String   cooardinates = document.get("coordinates").toString();

 } else {
                            kProgressHUD.dismiss();

                            Log.d("", "Error getting documents: ", task.getException());

                        }

                    }
                });


    }

Problem :

I’m using Firestore and trying to get all the documents under the root collection. I’m facing strange behaviour, I gets only those documents which were I added manually. I tried this, this and many other solutions like these but not getting all the documents.

Here’s my Firebase structure

enter image description here

One more thing which is noticeable, the 1st document under users collection which had I added by code looks italic and the other one looks normal & I’m only getting 2nd one in the logcat which is added manually.

Here’s my code

FirebaseFirestore.getInstance().collection("users")
                .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                        if (task.isSuccessful()) {
                            for (QueryDocumentSnapshot document : task.getResult()) {
                                Log.e("===>>>>", document.getId() + " => " + document.getData());
                            }
                        } else {
                            Log.d("===>>>>", "Error getting documents: ", task.getException());
                        }
                    }
                });

Here’s my logcat

READ  [ANSWERED] java - How do you check if the time (hour) is equal to?
Powered by Inline Related Posts

enter image description here

What is the proper way to get all the doc, does’t matter it should be added by code or manually!

Comments

Comment posted by Ashish

It’s because there is no data inside your document. You have created sub collection in your document

Comment posted by Doug Stevenson

On Stack Overflow, don’t share images with text. Copy the text into the question and format it so that it’s easy to read.

Comment posted by Irfan Akram

@Ashish – there’s also no data in the 2nd doc except a sub-collection but it is appearing in the console.

Comment posted by Irfan Akram

Then what if I want to get the id of that doc?

Comment posted by Doug Stevenson

With a normal query, you can’t. Documents that don’t exist can’t be queried by web and mobile clients. You should create an actual document there and populate it with a field that helps you find the document in a query.

Comment posted by Irfan Akram

Is there any way around to get the doc id which does not appear in queries or what else can I do with it?

Comment posted by Doug Stevenson

You will need to use a backend SDK to find it. If you have a new question please post it separately.

Comment posted by Irfan Akram

there is a data in the sub-collection named as “profileDetails”. Both doc have same data in it.

Comment posted by Adnan Bashir

then you use “` document.get(“profileDetail”).toString(); “` if profileDetail is a list or a hashmap then you cast it to list or map

READ  [ANSWERED] android - AndroidX Room generated class error: "Class is public, should be declared in a file named class.java"
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress