0

I want to list all the documents ID's from a collection. I have found some code that allowed this but it worked only for the documents that contains data but not for that ones that contains other collections (and documents and data). I used this code:

coordenadasCloud.collection("UbicacionTP").get().
        addOnCompleteListener(object: OnCompleteListener<QuerySnapshot> {
            override fun onComplete(p0: Task<QuerySnapshot>) {
                if(p0.isSuccessful){
                    val list: MutableList<String> = ArrayList()
                for (document in p0.result) {
                        list.add(document.id)
                    }
                    Log.d("huella", list.toString())
                } else {
                    Log.d("huella", "Error en obtener documentos", p0.exception)
                }
            }

        })

In my firestore database I have 3 documents inside "UbicacionTP". Two of them have just hashmap data and the other("permisos") has subcollections with more documents inside, this document id ("permisos") are not listed in the result on Logcat. Please help me with this issue, maybe I'm missing some code for that documents containing subcollections. Thanks

Principal collection with documents whose IDs I want to retrieve

Subcollections of the only one document that is not shown in the list of documents ID

  • There's no way to query such paths through the SDK. See https://stackoverflow.com/a/65670034, and https://stackoverflow.com/a/62987892 (read the question mostly there, as it contains a -possibly expensive- workaround). – Frank van Puffelen Jul 14 '21 at 05:30
  • Please edit your question and add your database structure as a screenshot and indicate the exact document IDs you want to get. – Alex Mamo Jul 16 '21 at 06:53
  • Hello, @FrankvanPuffelen , I understand, I had to change the structure of my firestore database. Thanks for the help! – Rolando Rodriguez Jul 23 '21 at 04:38
  • Hello, @AlexMamo, the structure of my firestore database was like this: `Collection1---> Document1.1---> Collection2---> Document2.1` I had several Documents, like 1.1, 1.2, 1.3, 1.4 and so on, and the same structure inside, so I wanted to retrieve the list of the docs ID of Document 2.1, 3.1, 4.1 and so on. thanks for the help! – Rolando Rodriguez Jul 23 '21 at 04:53
  • Instead of describing how your database looks like, please edit your question and add a screenshot of it. – Alex Mamo Jul 23 '21 at 05:20
  • Hello, @AlexMamo, I added two screenshots. As I explained, when I get the result, just retrieve the document ID of "joseluisrodriguez" and "rolandorodriguez", I expected to obtain "permisos" too but this one is not shown (maybe because it has more subcollections inside). Thanks for the help – Rolando Rodriguez Jul 24 '21 at 00:57
  • So what exactly would you like to get? Which data? – Alex Mamo Jul 24 '21 at 09:12
  • Hello, I want to get the list of documents ID, lika: [joseluisrodriguez, permisos, rolandorodriguez], when I use the code shown I only get [joseluisrodriguez, rolandorodriguez], this occur maybe because "permisos" has subcollections with more data inside, the other documents just have hashmap data. Thanks – Rolando Rodriguez Jul 25 '21 at 11:49

0 Answers0