Skip to content

Instantly share code, notes, and snippets.

@doubleshow
Created September 28, 2014 15:00
Show Gist options
  • Save doubleshow/12ad9561203e6771bd2d to your computer and use it in GitHub Desktop.
Save doubleshow/12ad9561203e6771bd2d to your computer and use it in GitHub Desktop.
Retrieve a list of repositories from Github and store them in a mongodb collection
var rest = require('restler');
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
if(err) throw err;
console.log(">> Dropping collection");
db.dropCollection('test_insert_github', function(err, result) {
console.log("dropped: ");
console.dir(result);
});
rest.get('https://api.github.com/repositories').on('complete', function(data) {
// Create a collection to store the results from github
var collection = db.collection('test_insert_github');
collection.insert(data, function(err, docs) {
// Locate all the entries using find
collection.find().toArray(function(err, results) {
results.forEach(function(x){
console.log("name:" + x.name + ", owner.login:" + x.owner.login);
});
// Let's close the db
db.close();
});
});
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment