Source: https://firebase.google.com/docs/firestore/quickstart
Video: https://www.youtube.com/watch?v=2Vf1D-rUMwE
- Create a project at https://console.firebase.google.com/u/0/
- Create a databse from the Database Console
- Go to General and start with the Web platform under Your Apps
npm install -g firebase-tools --save
- Get config from Firebase SDK snippet and save in an environment file
- In the database console, go to the rules tab and change false to true in line 5
npm install firebase --save
const firebase = require("firebase"); //Firebase App (the core Firebase SDK) is always required and must be listed before other Firebase SDKs
require("firebase/firestore"); // Add the Firebase products that you want to use
firebase.initializeApp(firebaseConfig); // Initialize Firebase
var db = firebase.firestore(); //Initialize an instance of Cloud Firestore
db.collection(collectionName).add({
fieldName: fieldValue
})
.then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
db.collection(collectionName).get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(`${doc.id} => ${doc.data().fieldName}`);
});
});