chintoo
chintoo

Reputation: 27

Using Cloud9 IDE - trying to connect to my mongodb

M using Cloud 9 IDE. I'm following this guide to learn: http://cwbuecheler.com/web/tutorials/2013/node-express-mongo/

I have a folder called data which has my mongodb db.

In my app.js, I have the following code:

var mongo = require('mongodb');
var monk = require('monk');
var db = monk('process.env.IP:process.env.port/nodetest1');

I'm wondering if this is correct, because following the guide I created a db, added 3 elements to it, created a Jade file, added it to my routes.

However, I get a 500 code error in my server, and also this when I navigate to the /userlist page:

/home/ubuntu/workspace/near-me/views/userlist.jade:7 5| User List 6| ul > 7| each user, i in userlist 8| li 9| a(href="mailto:#{user.email}")= user.username Cannot read property 'length' of undefined

TypeError: /home/ubuntu/workspace/near-me/views/userlist.jade:7
5| User List
6| ul
> 7| each user, i in userlist
8| li
9| a(href="mailto:#{user.email}")= user.username

Cannot read property 'length' of undefined
at eval (eval at <anonymous> (/home/ubuntu/workspace/near-me/node_modules/jade/lib/index.js:218:8), <anonymous>:50:31)
at eval (eval at <anonymous> (/home/ubuntu/workspace/near-me/node_modules/jade/lib/index.js:218:8), <anonymous>:93:4)
at eval (eval at <anonymous> (/home/ubuntu/workspace/near-me/node_modules/jade/lib/index.js:218:8), <anonymous>:106:22)
at res (/home/ubuntu/workspace/near-me/node_modules/jade/lib/index.js:219:38)
at Object.exports.renderFile (/home/ubuntu/workspace/near-me/node_modules/jade/lib/index.js:380:38)
at Object.exports.renderFile (/home/ubuntu/workspace/near-me/node_modules/jade/lib/index.js:370:21)
at View.exports.__express [as engine] (/home/ubuntu/workspace/near-me/node_modules/jade/lib/index.js:417:11)
at View.render (/home/ubuntu/workspace/near-me/node_modules/express/lib/view.js:126:8)
at tryRender (/home/ubuntu/workspace/near-me/node_modules/express/lib/application.js:639:10)
at EventEmitter.render (/home/ubuntu/workspace/near-me/node_modules/express/lib/application.js:591:3)

Anyone have any idea what I am doing wrong? The author of the guide asked me to check the github for the jade file, which I did and it seems OK.

I'm thinking its my server config but I'm too stupid/new to figure it out. I tried changing to var db = monk('process.env.IP:28017/nodetest1'); and still get the same issue.

EDIT

Managed to fix it. First, run the following in mongo console:

db.serverCmdLineOpts()

This will show the IP and port. In C9 you have to use 0.0.0.0:27017 in your app.js or equivalent.

Upvotes: 2

Views: 185

Answers (1)

dbenson
dbenson

Reputation: 326

For future searches,

var db = monk('localhost:27017/dbname');

Is all that is necessary to connect to the DB.

Upvotes: 1

Related Questions