watson / mongodown

A drop-in replacement for LevelDOWN that runs on MongoDB
MIT License
29 stars 16 forks source link

Auth issues when creating databases in MongoLab #4

Closed fiatjaf closed 9 years ago

fiatjaf commented 9 years ago
var levelup = require('levelup')
var mongodown = require('mongodown')
var db = levelup('myuser:mypassword@ds984753.mongolab.com:53798/pliplu', {db: mongodown})
db.put('key', 'value')

Should create a dabatase and put a document in it, right? But it doesn't. It fails with a MongoError: auth failed.

Everything works if I precreate the database in the MongoLab console, but I cannot make mongodown create the databases for me.

I don't understand the workings of MongoDB, so this is maybe a stupid question, but thank you for the help.

watson commented 9 years ago

You need special permissions to create databases, and I guess your account on MongoLab doesn't allow that but from within the admin interface. If you ran this against an instance of MongoDB where you have admin privileges it should work (like when you run it locally for instance)

fiatjaf commented 9 years ago

You're right.

So, instead of taking the time to learn all the inner workings of MongoDB, I'll ask you a question: what if instead of creating new databases, mongodown used a new collection for every new database LevelUP asked? Would it work? Would it be acceptable? The code would have to be changed too much?

(I'm not asking for you to change anything, I'm thinking about forking the project and adapting it if you tell me it is a good idea.)

watson commented 9 years ago

@fiatjaf it's not possible with mongodown in the current version, but I'll release a version ASAP which will allow you to override the name of the collection. That way you'll be able to do this. I'll let you know