Cloud Firestore is Firebase’s enhanced version of the realtime database. It is a NoSQL, Horizontally scaling, document modal database in the cloud which makes it very lucrative for developing fast, realtime, and scalable mobile and web apps.
Realtime database stores data in a JSON format where each key: value pair may contain simple data or another JSON object as the value. On the other hand in cloud Firestore the is stored as JSON but it uses a document modal.
Document Modal: Cloud Firestore Database structure
In Cloud Firebase data is stored as a JSON object but it is generalized into Documents and Collections. Here are the common Jargons used in cloud Firestore:
Documents, Collections, and Maps
A Collection is a collection of Documents and it is also always the root element.
A Document store your data as fields. which contains the key: value pairs where each key can contain a value or another JSON object which is referred to as a Map.
Now usually, a map is only used if the data is small otherwise a separate Document is recommended. Which can be referred by referring to its Collection.
Here are some other things you should know about the cloud Firestore database:
- A Document can never store another document as its child
- A Document can have an autogenerated unique id or you can give it a name by yourself
- A Document can never exceed in size more than 1mb. If so you are gonna have to split the document
- You can never point to a Document from another Document. You have to first Point to the collection and then the Document inside.
- The root of your DB can only be a Collection
- There are two ways you can point to a document in cloud Firestore:
- using
firestore().Collection(…).Document(…).Collection(…).Document(…)
- Using
Collection/Document/Collection/Document
For more complex paths