I’ve been using Cloud Firestore as my primary database for months now and have been very happy with it.

Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud Platform. Like Firebase Realtime Database, it keeps your data in sync across client apps through realtime listeners and offers offline support for mobile and web so you can build responsive apps that work regardless of network latency or Internet connectivity. Cloud Firestore also offers seamless integration with other Firebase and Google Cloud Platform products, including Cloud Functions.

Google’s description of Firestore is clear enough, but, for some reason, I have ignored the part about “keeps your data in sync across client apps through realtime listeners”. I think I ignored it because (a) I didn’t think I needed it and (b) I didn’t understand it.

Having grown up on SQL databases I am very comfortable with writing code to perform all database reads and writes. The concept of real-time updates just sounds like chaos! 😬

Not only is this not true but I will be using real-time updates from now on. Here’s how!

Traditional Queries

Until recently I was only pulling data from Firestore using traditional query methods. This is like using “SELECT” in an SQL statement. To retrieve data in the traditional manner, Firestore provides a get() method with several options:

  • Retrieve all documents in a collection

db.collection("cities").get()

  • Retrieve all documents of a collection group (subcollections across numerous collections)

db.collectionGroup("landmarks").get()

  • Retrieve select documents of a group (where clause)

db.collection("cities").where("capital", "==", true).get()

  • Retrieve a single document

db.collection("cities").doc("SF").get()

#vuex #realtime #vue #firebase #firestore

How to Add Real-Time Updates to your Vue App
54.05 GEEK