Regarding the actual limitations in querying data based on subcollections values, what is the suggested way to manage multitenancy in Firestore?
I would like to be able to retrieve and limit access to data related to entities/companies the user is part of.
Example data structure :
/companies/{companyId}/users/
/companies/{companyId}/users/{user}/roles
/companies/{companyId}/docs/
Can /companies/{companyId}/users/
be a collection?
How can I only retrieve companies where user own a role in /companies/{companyId}/users
?
Firestore paths alternate from collection to document and back again:
So yes, in this case, you would have collections of
companies
,users
, anddocs
. Collections are also implicit in that they are created automatically when documents exist in them, and removed when no documents exist in them.At present, subcollection queries (e.g. "all users in a given company") aren't supported, so you'll have to structure your query the other way around: having a users collection with company as a property, when performing a query to find all users in that company.