Created
          February 1, 2022 14:51 
        
      - 
      
 - 
        
Save SamMakesCode/c61b47793d762fe54b38a7d9f5015254 to your computer and use it in GitHub Desktop.  
    Firebase cheatsheet
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Firebase setup | |
| const admin = require('firebase-admin'); | |
| admin.initializeApp( | |
| // Your settings | |
| ) | |
| const db = admin.firestore() | |
| // Add a document to a collection | |
| db.collection("users").add({ | |
| forename: "Gandalf", | |
| surname: "The Grey" | |
| }) | |
| // Add a document with a specific id | |
| const docRef = db.collection("cities").doc("MT"); | |
| docRef.set({ | |
| name: "Minas Tirith", | |
| }) | |
| // Updating a document | |
| const docRef2 = db.collection("cities").doc("MT") | |
| docRef2.update({ | |
| oldName: "Minas Anor", | |
| }) | |
| // Get a document ID | |
| const docRef3 = db.collection("cities").doc("MT"); | |
| const docId = docRef3.id; | |
| // Get a document's data | |
| const docRef4 = db.collection("cities").doc("MT"); | |
| docRef4.get().then((snapshot) => { | |
| const data = snapshot.data(); | |
| }) | |
| // Delete a document | |
| db.collection("cities").doc("MT").delete(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment