-
-
Save ldonjibson/6b554f599f965ecacdb65f34ab5578c0 to your computer and use it in GitHub Desktop.
Firestore CRUD Cheat Sheet
This file contains 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
// Setup Firestore. Note that all of these will be asyncronous tasks and can have a .then attached. Write in a config process for Firebase. Include the necessary process.env files and instructions how to make a .env file. | |
*************************************************************** | |
// Add data - C | |
firestore.collection("CollectionName").add({ | |
key: value, | |
key: value, | |
}) | |
*************************************************************** | |
// Getting data - R | |
firestore.collection("CollectionName").get().then((snapshot) => {snapshot.docs.map(doc => { | |
console.log(doc) | |
}) | |
}); | |
!!------------------------!! | |
// If you require a search query | |
firestore.collection("CollectionName").where("key", "==", "value").get(); | |
*************************************************************** | |
// Update data - U | |
firestore.collection("CollectionName").doc(ID).update({ | |
key: newValue | |
}); | |
*************************************************************** | |
// Deleting data - D | |
firestore.collection("CollectionName").doc(ID).delete() | |
*************************************************************** | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment