0

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);
Chris Anderson
  • 666
  • 3
  • 4

1 Answers1

1

Yep. I was doing something dumb. Just in case this is helpful for any other noob... The http client runs on port 28017 but MongoDB itself is actually listening on port 27017. Note the "7" in the second position. Duh. The right connection parameter (in my case), then, would be "localhost:27017/test".

Chris Anderson
  • 666
  • 3
  • 4