My Firestore database structure looks like this (as shown in image)
I have a users collection which has a posts sub-collection.
I want to fetch(query)all the posts by country(field of parent collection). Edited: I have other's fields too along with country field, so I don't want to duplicate fields in posts sub-collection.
Is there any solution without any duplication of fields.
My code is below:
val query: Query =
postsRef
.whereEqualTo("country", "USA"). // field from parent document
.orderBy("createdAt", Query.Direction.DESCENDING)
.limit(20)