Skip to content

Instantly share code, notes, and snippets.

@arliber
Last active March 27, 2017 15:18
Show Gist options
  • Save arliber/55440c32111ef5bf98c4f31f6f18cc22 to your computer and use it in GitHub Desktop.
Save arliber/55440c32111ef5bf98c4f31f6f18cc22 to your computer and use it in GitHub Desktop.
#!/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