Last active
January 2, 2019 06:40
-
-
Save kobvel/794639987bfbc20d960d25921194c03f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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