watson / mongodown

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

Configurable collection name #6

Closed bassjacob closed 7 years ago

bassjacob commented 7 years ago

Hi,

I'm looking to use this package as part of some framework code and I think it would be useful to be able to set the collection name as part of the constructor. Is that behaviour that you'd be interested in?

watson commented 7 years ago

Sure, that would be nice 😃 Are you interested in making a PR?

watson commented 7 years ago

There where actually an attempt to do this last year in this PR: https://github.com/watson/mongodown/pull/3 - maybe you can learn something from that 😃

bassjacob commented 7 years ago

That was what sparked my interest :smile: I'm in still in discovery mode for the feature, but I'm happy to take a stab at it. The "query string" approach looks fine to me, obviously as long as levelup doesn't ship a conflicting query param name. Would you be ok with something like:

var db = levelup('localhost/my-database?mongodown_collection=foo', { db: require('mongodown') });
watson commented 7 years ago

As far as I know levelup doesn't use that string for anything. It just passes it directly into the db instance. So I think we're free do do with it what we want. So we could just call it collection and then separate it from the self.location string inside the _open function. Or even better, already in the constructor function before passing it into AbstractLevelDOWN