Daniel
Daniel

Reputation: 1267

Firestore - Multiple Collections or Subcollections per each account

I have a software that has 10 Collections per Account. And the software will have at most 1000 Accounts

Whats would be the best practice on terms of cost and clean code?

Option 1: 1K collections and 10 Subcollections each.

Option 2: 10k Collections with an extension on the name, something like: "_clientName"

What I've understood by now:

The use of Subcollections duplicate the amount of queries.

Upvotes: 1

Views: 191

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317657

You will have a very hard time with security rules with option 2. In general, there should not be collections with concatenated strings in them, because you will have to list them out individually in your rules. That means you'll have to type 10K rules, and you'll risk running out of space for those rules. Option 1 will make it easier to match collections and subcollections with wildcards.

The cost between them is the same. You are charged for the total number of documents read, not the number of queries performed. I suggest studying the Firestore pricing documentation to better understand what the costs are.

Upvotes: 3

Related Questions