Firestore
Cloud Firestore follows NoSQL model, in which you store data in documents that contain fields mapping to values. These documents are stored in collections, which are containers for your documents that you can use to organize your data and build queries. Documents support many different data types, from simple strings and numbers, to complex, nested objects. You can also create subcollections within documents and build hierarchical data structures that scale as your database grows.
#
Intiliaze Cloud Firestore#
Add dataHere Cloud Firestore creates collection and document implicitly the first time we add to the document. It returns a promise which should be handled accordingly. Also, if needed it returns document reference and docRef.id can be extracted for that particular document.
#
Read dataYou can use get() method to retrieve a document or even an entire collection.
#
Update elements in an arrayIf your document contains an array field, you can use arrayUnion()
and arrayRemove()
to add and remove elements. arrayUnion()
adds elements to an array but only elements not already present. arrayRemove()
removes all instances of each given element.
#
Perform simple and compound queriesHere we fetch events from firestore(more detail in the next section) according to the filter provided. We fetch all the documents which satisfies our paricular queries.
#
Order and Limit dataBy default, a query retrieves all documents that satisfy the query in ascending order by document ID. You can specify the sort order for your data using orderBy(), and you can limit the number of documents retrieved using limit().
#
Paginate data with query cursorsQuery cursors define the start and end points for a query, allowing you to:
- Return a subset of the data.
- Paginate query results.
Paginate queries by combining query cursors with the limit() method. For example, use the last document in a batch as the start of a cursor for the next batch.
#
Useful Resourcesimportant
It is recommended for this section to visit firestore docs once.
Also, checkout Usage and limits for firestore.