Cloud Firestore is a document database. It is a scalable and versatile NoSQL cloud database.
Firestore is serverless; it eliminates the chance of hitting storage or operational restrictions since users need not provide infrastructure quotas in advance. In addition, by utilizing responsive listeners, Firestore maintains your data synchronized among client apps. It also offers offline responses to web and mobile applications, allowing you to create flexible applications independent of network delay or internet access.
Cloud Firestore's features include flexibility, descriptive querying, quick updates, offline help, and its built-to-scale architecture.
Cloud Firestore Data model
Cloud Firestore is a NoSQL, document-oriented database that stores data as 'documents' sorted into 'collections'.
A set of key-value pairs make up a document, and it is best to save vast quantities of small documents in Cloud Firestore.
Collections are needed to keep documents. Subcollections and nested objects, which can comprise simple fields like strings or sophisticated objects like lists, can be present in documents.
In Cloud Firestore, collections and documents are generated on the go. When you include data to a document inside a collection, Firestore generates the collection or document if one or both are missing.
Documents
The document serves as the primary storage unit in Cloud Firestore. A document is a concise record with fields that relate to values. In addition, a name is used to recognize the individual document.
Value data types supported by Cloud Firestore include boolean, integer, text, geo point, binary blob, and timestamp. Additionally, you may utilize maps (nested objects) or arrays to organize data inside a document.
A good illustration of a document showing a customer named Abdullah is as follows:
Abdullah first:”Abdullah” sur: “Kampo” email: “Adullah.Kampo@dataengineeringgcp.substack“ id: 89765434567
The above example can also use a mapping on the customer’s name.
Abdullah
name first:”Abdullah” sur: “Kampo” email: “Adullah.Kampo@dataengineeringgcp.substack“ id: 89765434567
Collections
Collections are merely storage facilities for documents. For instance, you might have a customer collection with all of your customers defined by individual documents.
Since Cloud Firestore is without a schema, you control the fields you include per document and the data types stored. The documents in a collection may have diverse areas or may hold various kinds of data in their fields. Users should utilize similar fields and data types in documents to simplify querying.
All the items in a collection must be documents. It's not authorized to directly store raw fields with values or other collections. The names of documents in a collection are distinct. There is no requirement to "create" or "remove" collections. Firestore handles all of this automatically when you create the first document in a collection or remove all of the documents in a collection.
A good illustration of the customer collection with all of your customers defined by individual documents is as follows:
Customers Abdullah first:”Abdullah” sur: “Kampo” email: “Adullah.Kampo@dataengineeringgcp.substack“ id: 89765434567 Dayo first:”Dayo” sur: “Krooozy” email: “Dayo.Krooozy@dataengineeringgcp.substack“ id: 67285934467
Cloud Firestore also contains other data models that help with data storage and retrieval, namely:
References: Unique document path in the Firestore database
Hierarchical Data: Implementation of hierarchical data structures.
Subcollections: collection related to a particular document.
Indexing and Querying
Single-field indexes and Composite indexes are the two classifications of indexes used by Cloud Firestore. All the documents in a collection with a particular field are saved in a single-field index through an arranged map. Following an organized list of fields to index, a composite index keeps a categorized mapping of every document within a collection.
When querying, Firestore uses indexes, which must be present for every document in a collection. Many fundamental queries in Cloud Firestore are handled using single-field indexes. The automated indexing settings and index exemptions of your database are designed to maintain single-field indexes.
Due to the vast number of potential field combinations, Cloud Firestore will not immediately implement composite indexes as it would for single-field indexes. Alternatively, while developing an application, Cloud Firestore assists you in discovering and designing the necessary composite index. Every composite index can only contain one array field.
Importing and Exporting
Firestore export and import service allows you to export data for offline operations or retrieve lost or damaged data. You can export and import all documents or only selected collections. A Cloud Firestore database may import data exported from another database. Additionally, you can also import Firestore outputs into BigQuery.
Check out the video below for a step-by-step guide on importing data to a Firestore database.