Category Archives: Database

Mongo Auth

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.

MySQL Source

I just fell in love with mysql “source”-command … just wanted to mention that ;-)!

Having trouble importing a large file into a mysql database? Simply open the prompt, connect to the server (on my local machine I didn’t need to specify a host) so something like:

mysql -u [user] -p

And as soon as mysql lets you in, you can select the database to import your file into with the command:

use [database]

After the database is selected, you can import your file with this little nugget:

source [file]

All commands without brackets 😉 … and mysql will start importing the data into your database. No more workbench messages like “unable to allocate sufficient bytes to read the file”. Live can be so easy!