Last active
March 27, 2017 15:18
-
-
Save arliber/55440c32111ef5bf98c4f31f6f18cc22 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/mongo --quiet | |
//Load data | |
print("Loading data..\n"); | |
load('data.js'); //The file from Firebase | |
//Connect to MongoDB | |
var db = connect("localhost:27017/MyDatabase"); | |
//Add collections | |
for(collection in data) { | |
print("Working on collection " + collection + ".."); | |
//Delete any previous data.. | |
db[collection].remove({}); | |
for (key in data[collection]) { | |
var doc = data[collection][key]; | |
doc.firebaseId = key; //Add the object key to the new document, for later reference | |
db[collection].insert(doc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment