Home > database >  how to access all documents from all subcollections having same collection Id
how to access all documents from all subcollections having same collection Id

Time:08-08

I have a collection named " categories " and in that I have 5 documents and every document is having a Collection named "Images" , and the Collection("Images") which is in all the five documents have a field named "artist_name" !

I want to access all the documents from every collection having id "Images" with same artist_name screenshot 2 screenshot 1

CodePudding user response:

What you are looking for, is called a collection group query. So to get all documents from all sub-collection where artist name == "grajoy", you should use the following query:

val db = Firebase.firestore
val queryByArtistName = db.collectionGroup("images").whereEuqlTo("artist_name", "grajoy")

Be aware that the collection is called images, and not Images (capital I), as I saw in the screenshot.

  • Related