-
-
Save hotsen/c75514203b3c28c22ecf0aac27791a51 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