Maximum size of a document in firestore?

The maximum size is roughly 1 Megabyte, storing such a large number of objects (maps) inside of a single document is generally a bad design (and 20 million is beyond the size limit anyway).

You should reconsider why they need to be in a document, rather than each object being their own document.

Cloud Firestore's limits are listed in the documentation.


If you want to save objects bigger than 1mb you should use cloud storage, the limit is 5tb per object:

There is a maximum size limit of 5 TB for individual objects stored in Cloud Storage. There is an update limit on each object of once per second, so rapid writes to a single object won't scale. Google cloud storage


Have you looked at Firestore sub-collections?

You can store the main item as a document in one top-level collection, and all of its underlying data could be in a sub-collection of that document.

There is no limit to how many object records a sub-collection can contain when those objects are stored as child documents of that sub-collection.

So 20M records should not be an issue.