I'm totally new with all the technologies I'm trying to do this with, but I have what seems like some simple code (gleaned from a tutorial) that I just can't get to work. I'm using Node, Express and Mongoskin/MongoDB. Whenever I try any operation against the db, I get a very generic "connection closed" error. I've got MongoDB 2.4.6, Mongoskin 0.6.0 and Mongo Native 1.3.19. MongoDB is running and I can connect from the terminal and work with my db. I see in the Mongo logging that my code never even establishes a connection. I thought maybe I need to call open explicitly, but even that returns the same error.
I'm sure I'm doing something dumb, but I'm stumped and help would be appreciated. Here's the code:
var express = require("express");
var mongoskin = require("mongoskin");
var db = mongoskin.db("localhost:28017/test", { safe: true, auto_reconnect: true });
var app = express();
app.get("/", function(request, response){
db.collection('testResult').find(function(error, result){
if (error) {
response.send("Find failed: " + error);
}
else {
response.send("got it ");
}
});
});
app.listen(8888);