Created
October 18, 2017 16:19
-
-
Save JoeRoddy/1c706b77ca676bfc0983880f6e9aa8c8 to your computer and use it in GitHub Desktop.
Convert Firebase Database JSON to Firestore Collections
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
var db = firebase.firestore(); | |
var content = require("./sourceData.json"); | |
content && | |
Object.keys(content).forEach(contentKey => { | |
const nestedContent = content[contentKey]; | |
if (typeof nestedContent === "object") { | |
Object.keys(nestedContent).forEach(docTitle => { | |
firebase | |
.firestore() | |
.collection(contentKey) | |
.doc(docTitle) | |
.set(nestedContent[docTitle]); | |
}); | |
} | |
}); |
Thank you!
Worked perfectly, thanks allot JoeRoddy!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this will run you out of stack and memory if your input json is too large, as all those set calls are async