Among its services, Firebase also provides a database.
Actually, you can choose between two databases: Realtime Database and Cloud Firestore.
The Cloud Firestore is newer, has a more intuitive data model and is more scalable, so that’s the database that we’ll be using. There are scenarios where you might prefer to use the Realtime database though, specifically when you need several databases for a single app.
Both are NoSQL document databases that allow storing, querying, and updating data in the cloud. And more importantly for you as a Flutter developer, you can use them as the backend for your apps, with no need to write the code for a web service and, in many cases, without writing any code at all for your server-side web api.
Now, for the Cloud Firestore database, you put your data into Collections. Collections in turn contain Documents. Documents are basically key value pairs. If you are familiar with JSON, well, it’s a bit like JSON files. For example, if you want to create a Collection of cars, you can name the Collection CARS. Each car you put in the collection is a Document, and each document has a few keys, like Brand, model, year, color and so on. For each key, you place a value, so for the color KEY you can set a RED value, and so on.
There are a few rules though:
Collections can only contain documents, not other collections.
A document cannot contain another document.
But A document CAN contain a collection (or SUB collection in this case), which can then contain other documents.
Documents can take up to 1 MB of space, which I guess is more than enough for most use cases
The Firestore root can contain one or more collections but not any document: again, documents must be in a collection.
To sum it up, in a Firestore database contains collections, collections contain documents, and documents contain collections, and so on.
OK, let’s create our first Firestore database and connect to our app next!