2

I have a Firestore database see the image below. I want to retrieve the doctor's info. All of these documents under "doctors" collection are from authenticated users and I have saved the documents with their IDs. I am using this code to get the documents but it returns 0. I think the problem is authentication. Kindly help me to solve this issue.

 val query = fireStoreDbRef.collection(Constants.COLLECTION_DOCTORS)
        query.get().addOnSuccessListener {
        Log.d("TAG", "getAllDoctors: "+it.size())
    }

enter image description here

Security Rules I am using enter image description here

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Yazdan Ilyas
  • 374
  • 4
  • 8
  • I don't think the issue here is the Auth, since you commented out the auth rule allowing access to everyone. A few things you can check is if the value of `Constants.COLLECTION_DOCTORS` is what you expected to be and not use the `it` operator in the sucessListener, instead do like described in the [documentation](https://firebase.google.com/docs/firestore/query-data/get-data#get_multiple_documents_from_a_collection) and use the `documents` result. Can you try that? – Ralemos May 31 '21 at 12:23
  • @RafaelLemos Thank you for replying. I have tried accordingly everything is fine but yields me nothing. \n fireStoreDbRef.collection("doctors").get().addOnSuccessListener { documents -> for (document in documents) { Log.d("TAG", "${document.id} => ${document.data}") } } .addOnFailureListener { exception -> Log.d("TAG", "Error getting documents: ", exception) } – Yazdan Ilyas Jun 01 '21 at 07:13
  • 1
    I just realized that in your console the documentIds are in italic, this is not the normal display, which indicates that these documents had been deleted. Try adding a new document to that collection and try querying it, it should be working by then. – Ralemos Jun 01 '21 at 12:54
  • @RafaelLemos Thank you, You were right it's because of that italic documents I have added a document manually to the collection and it's working. But now I want to know why these documents turned italic as they are not deleted and there is data present in it. – Yazdan Ilyas Jun 02 '21 at 09:52
  • I have found the answer to why documents are italic and how to handle them. It's helpful https://stackoverflow.com/questions/48137582/firestore-db-documents-shown-in-italics – Yazdan Ilyas Jun 03 '21 at 15:27

1 Answers1

1

It's possible to see in your screenshot that the documentIds are in italic, this indicates that the documents you were trying to access were deleted. If you were to add a new document the code you currently have for fetching documents is suppose to work normally.

As per the reason why those documents were deleted, the most probable is that they were deleted by someone else operating this Firestore, unfortunately there are no native log solutions for Firestore for you to audit that. In fact, it is recommended that you build a logging solution for your Firestore with the use of Cloud Functions, if you fell it is necessary, here is an example in a community answer for how to do that.

If this is not the case I would advise you to keep an eye out for this behaviour, and if it should happen again I would recommend you to open a Bug Report on Google's Issue Tracker so that this can be troubleshooted by Google's Engineering team

Ralemos
  • 5,571
  • 2
  • 9
  • 18
  • 1
    your answers really helped me to reach the problem, Thank you so much. Kindly Upvote the question so it could be helpful to others. – Yazdan Ilyas Jun 03 '21 at 15:24
  • In that case, please also consider accepting and upvoting this answer as it provided you the solution for the issue you were facing and could be helpful to others. – Ralemos Jun 04 '21 at 09:23