PeterPazmandi
PeterPazmandi

Reputation: 581

Firestore: Query a doc from first collection, but order the list regarding the field of a different collection

I would like to implement a list of friends. When I open this list in my app, I would like to see it in ascending order. In my case I store the users in a collection, called "users", where the documents' id is the unique id of a user. The friends are stored in the "friends" collection, where you can see how is the requester, for whom is it sent, and is it accepted or not.

Is it possible to query the list of friends from the collection of "freinds", which is order by the field of "name" from the "users" collection?

enter image description here

enter image description here

Upvotes: 0

Views: 95

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317402

It's not possible. Firestore queries can only consider field values from documents in a single collection at a time.

What you will need to do instead is have a collection that involves all of the data you need for the query in a single collection. It's common to duplicate data like this in NoSQL type databases for the purpose of flexible querying - it's called "denormalization".

Upvotes: 2

Related Questions