Created
November 29, 2015 20:42
-
-
Save NathanMaton/2b773cd523fb122b04a3 to your computer and use it in GitHub Desktop.
pull prod user into habitrpg
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
//Load the request module | |
var request = require('request'); | |
var mongodb = require('mongodb'); | |
var user = [] | |
//Lets configure and request | |
request({ | |
url: 'https://habitica.com:443/api/v2/user', //URL to hit | |
//qs: {from: 'blog example', time: +new Date()}, //Query string data | |
method: 'GET', //Specify the method | |
headers: { //We can define headers too | |
'x-api-user': 'DELETED REAL KEY', | |
'x-api-key': 'DELETED REAL KEY' | |
} | |
}, function(error, response, body){ | |
if(error) { | |
console.log(error); | |
} else { | |
//console.log(response.statusCode, body.length); | |
console.log(response.statusCode, JSON.parse(body)); | |
user.push(body); | |
//console.log(user[0]["_id"]); | |
//We need to work with "MongoClient" interface in order to connect to a mongodb server. | |
var MongoClient = mongodb.MongoClient; | |
// Connection URL. This is where your mongodb server is running. | |
var url = 'mongodb://localhost:27017/habitrpg'; | |
// Use connect method to connect to the Server | |
MongoClient.connect(url, function (err, db) { | |
if (err) { | |
console.log('Unable to connect to the mongoDB server. Error:', err); | |
} else { | |
//HURRAY!! We are connected. :) | |
console.log('Connection established to', url); | |
// Get the documents collection | |
var collection = db.collection('users'); | |
//Create some users | |
/*var user1 = {name: 'modulus admin', age: 42, roles: ['admin', 'moderator', 'user']}; | |
var user2 = {name: 'modulus user', age: 22, roles: ['user']}; | |
var user3 = {name: 'modulus super admin', age: 92, roles: ['super-admin', 'admin', 'moderator', 'user']};*/ | |
// Insert some users | |
collection.insert(JSON.parse(body), function (err, result) { | |
if (err) { | |
console.log(err); | |
} else { | |
console.log('Inserted %d documents into the "users" collection. The documents inserted with "_id" are:', result.length, result); | |
} | |
//Close connection | |
db.close(); | |
}); | |
//db.close(); | |
} | |
}); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment