Skip to content

Instantly share code, notes, and snippets.

@diegograziano
Created June 29, 2019 03:20
Show Gist options
  • Save diegograziano/2e626174aeb39ee688deea9449639ec9 to your computer and use it in GitHub Desktop.
Save diegograziano/2e626174aeb39ee688deea9449639ec9 to your computer and use it in GitHub Desktop.
const firebase = require("firebase");
// Required for side-effects
require("firebase/firestore");
// Initialize Cloud Firestore through Firebase
firebase.initializeApp({
apiKey: "<YOUR API KEY>",
authDomain: "<YOUR AUTH DOMAIN>",
projectId: "<YOUR PROJECT ID>"
});
var db = firebase.firestore();
var menu =[
{
"id":1,
"name":"Focaccia al rosmarino",
"description":"Wood fired rosemary and garlic focaccia",
"price":8.50,
"type":"Appetizers"
},
{
"id":2,
"name":"Burratta con speck",
"description":"Burratta cheese, imported smoked prok belly prosciutto, pached balsamic pear",
"price":13.50,
"type":"Appetizers"
}
]
menu.forEach((obj) => {
db.collection("menu").add({
id: obj.id,
name: obj.name,
description: obj.description,
price: obj.price,
type: obj.type
}).then((docRef) => {
console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
console.error("Error adding document: ", error);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment