I have a collection called 'posts' and I have 11 documents in it. This is my database:
Each document contains an image. So , i have created an activity which displays the images in each document in a recyclerview. And when I click on any image, it send the postId to a second activity which shows the rest of the fields of that particular document in the second activity. I use the following code to retrieve document fields in the second activity:
DocumentRefernce docRef = FirebaseFirestore.getInstance()
.collection("posts")
.document(postId)
.get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>()
{
@Override
public void onSuccess(DocumentSnapshot documentSnapshot)
{
System.out.println("DC Exists: " + documentSnapshot.exists());
System.out.println("DC ID: " + documentSnapshot.getId());
}
});
All the images are displayed fine in the first activity and the postId is send successfully to the second activity. But the problem is when I run the above code,for some documents, documentSnapshot.exists()
returns false
, but I am able to retrieve the id with documentSnapshot.getId()
properly for all the documents. Also, all documents have same fields. Is there anything wrong with the code?
Edit:
I have tried this with the OnCompleteListener
, and still some documets return false
when called exits()
. It is not throwing any exceptions.