Can't access MongoDB from subdomain on same server

I am running NginX, Node and Mongodb. And it seems that I can't acces the same database from a second app I am running. For example, I don't get anything back when I do:

collection.findOne({
    name: someName
}, function(err, results){
    // Returns no errors or results. Just stops working.
});

I can access the database perfectly fine from my first app, but not the second one. This is the code I use to connect to the database in both apps.

Server = require('mongodb').Server,
Db = require('mongodb').Db,
db = new Db('database', new Server('localhost', 27017, { auto_reconnect: true }), { w: true });

Anyone know what the problem might be?

Edit: Does it have something to do with the subdomain or ports? Too many connections?

Edit 2 (more info):

I run mongodb with service mongodb start.

In my /etc/mongodb.conf I have bind_ip = 127.0.0.1 and dbpath=/var/lib/mongodb (rest is default)

In both my apps I run the same code to establish a connection to the database, but only the first one works (I know that because I am able to retrieve information from the database in my first app).

The apps are running on different ports. The first one is running on port 1337 and the second one runs on 3000.

You are using 'localhost' as the host name to connect to this server.

This means you will only be able to connect from the same machine that mongod is running on with that hostname.

Unless all your apps run on the same server as mongod you will need to change your connect code to use the actual hostname of the mongod server.