Skip to content

Instantly share code, notes, and snippets.

@SamMakesCode
Created February 1, 2022 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamMakesCode/c61b47793d762fe54b38a7d9f5015254 to your computer and use it in GitHub Desktop.
Save SamMakesCode/c61b47793d762fe54b38a7d9f5015254 to your computer and use it in GitHub Desktop.
Firebase cheatsheet
// 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