Jump Start Node.js - First Chapter Help

I’m reading Jump Start Node.js and the first example in the first chapter covers a lot of topics. In it we create a form that allows people to create a MongoDB dataset of a username/password. I’ve followed the example to the very end, but can’t get the database to update.

I can’t figure out what is wrong. Help! There aren’t any typo’s in the code and I’ve followed the text exactly. My only guess is it’s not connecting to the database for some reason and I have no idea why. At the first part of the chapter we had to install express and I wasn’t able to do it, but following some other forums I figured out how to get around my proxy. Could that be my issue? I need to get around my proxy for the app?

I tried on another computer and still couldn’t get it to work. But now I have the following error codes:

Error: Uncaught, unspecified “error” event. (not authorized for query on msharptestdb.system
.indexes)
at NativeConnection.emit (events.js:157:17)
at D:\SitepointBooks\authentication\node_modules\mongoose\lib\model.js:554:31
at D:\SitepointBooks\authentication\node_modules\mongoose\lib\utils.js:408:16
at D:\SitepointBooks\authentication\node_modules\mongodb\lib\mongodb\db.js:1066:28
at D:\SitepointBooks\authentication\node_modules\mongodb\lib\mongodb\db.js:1200:28
at D:\SitepointBooks\authentication\node_modules\mongodb\lib\mongodb\cursor.js:124:30
at D:\SitepointBooks\authentication\node_modules\mongodb\lib\mongodb\cursor.js:166:32
at D:\SitepointBooks\authentication\node_modules\mongodb\lib\mongodb\cursor.js:441:39
at Cursor.close (D:\SitepointBooks\authentication\node_modules\mongodb\lib\mongodb\curso
r.js:687:5)
at commandHandler (D:\SitepointBooks\authentication\node_modules\mongodb\lib\mongodb\cur
sor.js:441:21)

You can check out the first chapter free online here, and the part I’m having trouble with is everything after creating the basic form:
https://www.sitepoint.com/premium/books/nodejs1/online/ch01s02.html#d5e3523
they also have the code online here:

I doubt if I can be much help, sorry.

But just to be clear, the “Hello World” worked OK for you?

The trace looks to me like there’s a dependency problem. If you had trouble with the Package Manager then that is the most likely cause of your problems.

I’d say you’re not allowed to use the DB. have you set the MongoDB user correctly?

1 Like

The free version of MongoLab that they have you use in the book is pretty straight forward. There’s not really any user configurations you can change. If it helps, here’s the user configuration. I’ve check a million times and the user and password appear to be correct in my code.

{
“_id”: “msharptestdb.admin”,
“user”: “admin”,
“db”: “msharptestdb”,
“credentials”: {
“SCRAM-SHA-1”: {
“iterationCount”: 10000,
“salt”: “Wqesv8DGPlW0+iGafuSoIw==”,
“storedKey”: “bjVPw4ZRG1YtY07+RVNs9tQtQ5c=”,
“serverKey”: “Rk0jjV1N5y1vIvLiCB4xn4nsths=”
}
},
“roles”: [
{
“role”: “dbOwner”,
“db”: “msharptestdb”
}
]
}

I was able to get everything else working. Just can’t seem to connect to MongoLab.
Does anyone know of another tutorial I could follow to set up a locally hosted MongoDB and then try to connect to it with node.js/mongoose?

AFAIK you do not need to set a user/password for MongoDB (which would make the DB unprotected, but that would be OK for a local development system)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.