Just playing a little with mongodb and nodejs. Wanted to try out if there’s anything you have to take care of. Issues you wouldn’t expect.
So I created a node project (just a start.js), installed mongoose via npm (I read today that it’s a whole ORM for mongo, but that was the first driver that was recommended to me) and tried to connect:
mongoose.connect(‘uri’, options)
So I passed my credentials in the options object, but got the error message:
MongoError: auth failed
At first I thought I would have passed invalid credentials or had to choose the database first (but that is done via the uri). So I had a closer look at the message in the mongo host console itself. Well: UserNotFound … myuser@mydatabase … So I fired up MongoVUE (an admin UI for mongo) and double-checked that the user existed in the correct database.
Long story short: Mongo starts by default in a mode where no user is required. You have to pass “–auth” as parameter so the authentication module is loaded. After restarting mongo with:
.\mongod.exe –dbpath .\local_mongo –smallfiles –auth
Everything worked fine. I’m happy that I got one step further in understanding that stuff. And btw.: Without “–smallfiles” mongo was not able to start on my well filled harddrive, because the journal files where to big. But it might affect the performance, so I’ll remove that in the production-version.