I have been interfacing with twitter using nodejs. I'm trying to log some important public user data in a mongolab mongodb database. For some reason I keep getting a "topology destroyed error" I'm not quite sure why this is.
var Twitter = require('twitter');
var mongodb = require('mongodb');
var accounts = ['@zaynmalik',
'@ZooeyDeschanel'];
var client = new Twitter({
consumer_key: 'key',
consumer_secret: 'secret',
access_token_key: 'key',
access_token_secret: 'secret'
});
var MongoClient = mongodb.MongoClient;
var url = "mongodb://user:pass@mongolab.com:numbers/db";
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 database');
var collection = db.collection('accounts');
for(var i = 0; i < accounts.length; i++){
client.get('users/show', {screen_name: accounts[i]}, function(error, tweets, response){
if(error) console.log(error);
var account = {'screen_name': accounts[i], 'id': tweets.id};
collection.insert(account, {w:1}, function(err, result) {console.log(err);});
//collection.insert(account);
console.log(tweets.id); // Raw response object.
});
}
db.close();
}
});
As you can see the program establishes a connection to the database. Defines the collection and then iterates through a number of twitter accounts and logs pertinent information. The twitter requests are successful and the mongodb works with simple requests. If you have any ideas about why I'm getting this response please answer.