Home > Net >  Firebase storing a single document for general purpose
Firebase storing a single document for general purpose

Time:04-06

General question. I use Firestore to store docs. That's great for storing users, orders, etc. But say I want to store a single document with notification tokens of all admins of an app. What would you do then? creating a new collection with one document in it feels wrong and wasteful

CodePudding user response:

creating a new collection with one document in it feels wrong and wasteful

You can create a document for each notification, as Cloud Firestore is optimized for storing large collections of small documents. And when I say large, I mean extremely large.

But say I want to store a single document with notification tokens of all admins of an app.

You can indeed do that as long as the size of the document stays below the maximum limit. According to the official documentation regarding usage and limits:

Maximum size for a document: 1 MiB (1,048,576 bytes)

As you can see, you are limited to 1 MiB total of data in a single document. When we are talking about storing text, you can store pretty much but as your documents getts bigger, be careful about this limitation.

So, as long as you store data within this limitation, there will be no problem. If you think that you might get over this limitation, I recommend you store that data in two documents, or even three according to the number of tokens your app requires.

  • Related