I have a problem with the connection database MongoDB in Cloud9 Please help to resolve this issue!
var MongoClient = require("mongodb").MongoClient;
var port = process.env.PORT;
var ip = process.env.IP;
MongoClient.connect("mongodb://"+ip+":"+port+"/test",function(error,db){
if(!error){
console.log("We are connected");
}
else{
console.dir(error); //failed to connect to [127.4.68.129:8080]
}
});
Output:
Running Node Process
Your code is running at 'http://demo-project.alfared1991.c9.io'.
Important: use 'process.env.PORT' as the port and 'process.env.IP' as the host in your scripts!
[Error: failed to connect to [127.4.68.129:8080]]
If you follow https://docs.c9.io/setting_up_mongodb.html this link, you will setup and run your mongodb daemon under your workspace.
And if you take a look at the output of ./mongod
, you'll find out this output:
2015-08-22T12:46:47.120+0000 [initandlisten] MongoDB starting : pid=7699 port=27017 dbpath=data 64-bit host=velvetdeth-express-example-1804858
Just copy the host and port value to your mongodb config, set up the database url, in this case is:
mongodb://velvetdeth-express-example-1804858:27017