Skip to content

Instantly share code, notes, and snippets.

@dyaa
Forked from JoeRoddy/FirebaseToFirestore.js
Last active May 3, 2018 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyaa/4de7d88b3522c6c2400ab8ddd81e78a9 to your computer and use it in GitHub Desktop.
Save dyaa/4de7d88b3522c6c2400ab8ddd81e78a9 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