0

I would like to use a RecyclerView to retrieve a list of items from a primary collection. Inside each of these items, it is expected to have another collection, but some may not have it. Is it possible to make a query which checks the existence of the second collection for each item and displays only the ones with the second collection?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
E.Akio
  • 2,249
  • 3
  • 14
  • 27
  • See https://stackoverflow.com/questions/47997748/is-possible-to-check-if-a-collection-or-sub-collection-exists – Frank van Puffelen Aug 03 '19 at 13:24
  • The question you mentioned @FrankvanPuffelen asks if you can check "normally". What my question asks is if you can check it inside a query :) – E.Akio Aug 03 '19 at 14:13
  • The Firestore API has no knowledge of "normal" vs "inside a query", its behavior is the same. If you think there is a difference, it's easier to help if you edit your question to include code that show the context. See [how to create a minimal, complete, verifiable example](http://stackoverflow.com/help/mcve). – Frank van Puffelen Aug 03 '19 at 14:16
  • Both of you who replied to this question understood what it was meant to be achieved when it was said "a query". As far as I understood, the link you shared does have an implementable answer and mine doesn't, even if this is the answer. So both question are related to different aspects of Android implementation and practices as well as both have different answers. Please take more attention to your categorization of "duplicate". This question answer a different need from the one you shared. – E.Akio Aug 03 '19 at 16:24

1 Answers1

1

Is it possible to make a query which checks the existence of the second collection for each item and displays only the ones with the second collection?

No, it's not possible. There is no API that can help you check if a collection actually exists. A collection in Cloud Firestore only exists if there is at least one document in it.

The simplest solution might be to query for a single document within the second collection, and see if that query returns any results. That's it.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193