Created
August 29, 2012 19:46
-
-
Save adymitruk/3517845 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
var db = require('mongodb'), | |
server = new db.Server('alex.mongohq.com', 10053, {auto_reconnect: true}), | |
con = new db.Db('consentiment', server); | |
// callback: (err) | |
exports.connect = function(callback) { | |
con.open(function opened(err, db) { | |
if (err) return callback(err); | |
//return callback(false, db); | |
//return false; | |
console.log('connected to db'); | |
db.authenticate('adam', '', function authenticated(err, result){ | |
if (err) return callback(err); | |
if (!result) return callback(new Error('authentication failed')); | |
console.log('authenticated as adam'); | |
callback(err); | |
console.log('came back from call back'); | |
db.close(); | |
throw new Error('escape'); | |
}); | |
}); | |
} | |
// callback: (err, collection) | |
exports.getSubscriptions = function(callback) { | |
//callback(false, 'test'); | |
//return; | |
con.collection('companies', function(err, companies) { | |
if (err) return callback(err, null); | |
companies.find(function(err, cursor) { | |
cursor.toArray(function(err, companies) { | |
for (i=0;i<companies.length;i++) callback(err, companies[i].company); | |
}); | |
}); | |
}); | |
} |
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
//var url = require('url'); | |
var log = console.log; | |
//var twitter = require('./twitter.js'); | |
var dataaccess = require('./dataaccess.js'); | |
//twitter.get_tweets('telus', 0, function(tweets) { | |
//log(JSON.stringify(tweets, null, '\t')); | |
//}); | |
var main = function() { | |
dataaccess.getSubscriptions(function (err, company) { | |
if (err) throw err; | |
log(company); | |
}); | |
} | |
dataaccess.connect(function(err, db) { | |
if (err) throw err; | |
main(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment