0

I'm having this problem when trying to register a user on the database. The database template is a document specific to the registered user in which it has 3 arrays of objects.

I searched on the internet a little bit about it, and people seemed to say that creating a subcollection would solve it, but I don't get how it would solve the problem nor avoid it happening again in the future when theses arrays grow bigger since the subcollections are also limited by 1MB of size limit, or even needing to make multiple fetchs instead of only one if I understood it correctly.

I believed firestore was a database. Isn't it one? How can't I store data in a database then, being so limited? What's the logic behind Firestore for doing that?

And if so, how do I get around it so it never happens again?

AmodeusR
  • 33
  • 5

1 Answers1

0

The size limit of 1MB applies to each individual document. Subcollections are not part of it.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • So when it comes to saving thousands of data on Firestore, I have only 2 approaches? One is to save each individual registered user as a document in a subcollection and the other one would to save the array of users in a document and create another document when the previous one is near to 1MB? – AmodeusR Nov 14 '22 at 17:14
  • It's hard to give a generic answer here, but saving repeated values in a single document is indeed always going to be limited. Trying to stuff as much data as possible into a single document is a common anti-pattern, and usually means you should use separate documents in another (sub) collections straight away. --- If you're new to NoSQL/Firebase, I recommend reading [NoSQL data modeling](https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/) and watching [Get to know Cloud Firestore](https://firestore.video). – Frank van Puffelen Nov 14 '22 at 17:50