Skip to content

Instantly share code, notes, and snippets.

@Timtech4u
Forked from JoeRoddy/FirebaseToFirestore.js
Created November 24, 2017 10:36
Show Gist options
  • Save Timtech4u/69002b1e8bb98d1f81111914f122b9a7 to your computer and use it in GitHub Desktop.
Save Timtech4u/69002b1e8bb98d1f81111914f122b9a7 to your computer and use it in GitHub Desktop.
Convert Firebase Database JSON to Firestore Collections
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]);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment