## Three Ways to Access a Firebase Cloud Firestore Database ### Firebase Built-in Rest API * **API Endpoint** ``` https://firestore.googleapis.com/v1/projects/YOUR_PROJECT_ID/databases/(default)/documents/YOUR_COLLECTION_NAME/ ``` ### Firebase Functions SDK * **Node.js Environment** ```js const functions = require("firebase-functions"); const admin = require("firebase-admin"); admin.initializeApp(functions.config().firebase); const COLLECTION_NAME = functions.config().db.collection; let db = admin.firestore(); let collection = db.collection(COLLECTION_NAME); // Use doc, get, set, update and delete methods from collection. ``` ### Third-Party ORM/ODM * **Typesaurus ODM** ```js const { collection, add, set, update, get, remove, all, query, where } = require('typesaurus'); const functions = require("firebase-functions"); const admin = require("firebase-admin"); admin.initializeApp(functions.config().firebase); const COLLECTION_NAME = functions.config().db.collection; // Model type User = { name: string } const users = collection(COLLECTION_NAME) // Add a document to a collection with auto-generated id add(users, { name: 'Sasha' }) //=> Promise> // Set or overwrite a document with given id set(users, '42', { name: 'Sasha' }) //=> Promise> // Update a document with given id update(users, '42', { name: 'Sasha' }) //=> Promise // Get a document with given id get(users, '42') //=> Promise | null> // Get all documents in a collection all(users) //=> Promise[]> // Query collection query(users, [where('name', '===', 'Sasha')]) //=> Promise[]> // Remove a document with given id remove(users, '42') //=> Promise ```