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
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
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