I'm new to mongoose and javascript in general, and want to connect to a locally running mongodb. The following code give no errors, will perform all of the console logs except for the one inside the db.on('connected', function() call. The console log before that prints out a 1, and I can see on my mongodb terminal that a connection is being accepted. What am I missing here?
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/rawStockData');
https.get(requestURL, function(res) {
var data = '';
res.on('data', function (chunk) {
data += chunk
});
res.on('end', function() {
var jsonObj = JSON.parse(data);
console.log('Data Parsed');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
console.log(db.readyState);
db.on('connected', function() {
console.log('ConnectedToDatabase!');
});
});
});