scalable NoSQL cloud database to sync data for client and server-side development. Capabilities - Flexibility - Expressive Querying - Realtime Updates - Offline Support - Designed to Scale
Table based databases. - Tables which consists of n number of rows of data. - Predefined schema . - Vertically scalable NoSQL - Distributed database. - Document based, key-value pairs, graph databases or wide-column stores. - key-value pair, documents, graph databases or wide-column stores which do not have standard schema definitions which it needs to adhered to ie dynamic schema. - Dynamic schema for unstructured data. - Horizontially scalable
of key-value pairs. - Can contain subcollections and nested objects. - Identified by a name. - Supports a variety of data-types eg boolean, string, number etc. - Complex objects can be represented with maps. Example: ❒ _modge_ name: first : "Eoin" last : "Fogarty" born : 1900
contain other collections. - Do not create or delete, its implied. - Contained documents can contain different fields and types. Example: ❒❒ users ❒ _modge_ name: first : "Eoin" last : "Fogarty" ❒ heihei first : "Shawn" last : "Kawano"
your Android app. 2 - In build.gradle make sure to add google maven repository. 3 - Add firestore dependency. implementation 'com.google.firebase:firebase-firestore-ktx:19.0.0' 4 - Initialize Cloud Firestore. val db = FirebaseFirestore.getInstance()
use the set method val user = HashMap<String, Any>() user["name"] = "Eoin Fogarty" user["born"] = "1900" db.collection("users").document("_modge_") .set(user) .addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully written!") } .addOnFailureListener { e -> Log.w(TAG, "Error writing document", e) } If the document does not exist, it will be created. If the document does exist, its contents will be overwritten with the newly provided data, unless you specify otherwise
match statements, which identify documents in your database, and allow expressions, which control access to those documents: // Allow read/write access on all documents to any user signed in to the application service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if request.auth.uid != null; } } }
deploy Node.js code to handle events triggered by changes in your Cloud Firestore database. The Cloud Functions for Firebase SDK exports a functions.firestore object that allows you to create handlers tied to specific events. - onCreate: when a document is written to for the first time. - onUpdate: when a document already exists and has a value changed. - onDelete: when a document with data is deleted. - onWrite: when onCreate, onUpdate or onDelete is triggered.
to fire any time a new document is created in a collection by using an onCreate() handler with a wildcard exports.createUser = functions.firestore .document('users/{userId}') .onCreate((snap, context) => { // Get an object representing the document // e.g. {'name': 'Eoin', 'age': 119} const newValue = snap.data(); // access a particular field as you would any JS property const name = newValue.name; // perform desired operations eg send push... });