Skip to content

Instantly share code, notes, and snippets.

@kobvel
Last active January 2, 2019 06:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kobvel/794639987bfbc20d960d25921194c03f to your computer and use it in GitHub Desktop.
Save kobvel/794639987bfbc20d960d25921194c03f to your computer and use it in GitHub Desktop.
const admin = require('./node_modules/firebase-admin');
const serviceAccount = require("./service-key.json");
const data = require("./data.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://YOUR_DB.firebaseio.com"
});
data && Object.keys(data).forEach(key => {
const nestedContent = data[key];
if (typeof nestedContent === "object") {
Object.keys(nestedContent).forEach(docTitle => {
admin.firestore()
.collection(key)
.doc(docTitle)
.set(nestedContent[docTitle])
.then((res) => {
console.log("Document successfully written!");
})
.catch((error) => {
console.error("Error writing document: ", error);
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment