watson / mongodown

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

attempt playing around with some option to re-use connection #3

Closed bewest closed 7 years ago

bewest commented 9 years ago

Attempt to re-use an existing connection, via conn, and collection fields on the options.

watson commented 9 years ago

@bewest As you might have seen I finally got the tests to work and I was looking through your pull request again which is about adding two new features: Parsing in an existing MongoDB connection + setting the name of the collection to be used. Both are set as part of the options argument to the _open function, but I don't see how you are actually planning parse anything into this "private" method?

What is your specific use case?

Here is a different approach to set the name of the collection used (currently defaults to "mongodown"):

var db = levelup('localhost/my-database?collection=foo', { db: require('mongodown') });

Here I utilise the connection string options which doesn't have any known property called "collection" - so we are "free" to use that name to implement this functionality. What do you think about that approach?

bewest commented 9 years ago

Howdy @watson thanks for reviewing!

I'm looking to implement something like https://www.npmjs.com/package/lem, but for my Nightscout project which already exists using mongo

https://github.com/nightscout/cgm-remote-monitor/blob/mqtt/init/lib/storage.js

The code here (admittedly, not great) attempts to provide some kind of re-usable api where the connection to the database gets set up when the server boots, and then later on it can be customized/re-used with some specific logic, which may or may not include dedicating all future use cases of some context object to a specific collection. So the point of the patch was to separate connection time from the time when the collection is chosen.

The project, http://bewest.labs.diabetes.watch/ shows live glucose results for people wearing a continuous monitor. The code grew in popularity much much faster than we've been able to maintain it, so if you have any ideas, please let us know. I was looking at potentially using mongodown as a way to get nightscout's code into the level ecosystem, which is attractive for the modularity, pinning down versions, testing, etc. My first attempt was to separate the binding of the collection from the establishment of the connection.

watson commented 9 years ago

@bewest just to make sure I understand you: is it because you already have an established connection to mongodb from outside levelup and don't want to create new connections? OR is it because you want to control the timing of when the connection to the db is established?

bewest commented 9 years ago

Ah, I've already got an existing connection and would like to use it with a collection I name.

On Thu, Jan 22, 2015 at 5:15 AM, Thomas Watson Steen < notifications@github.com> wrote:

@bewest https://github.com/bewest just to make sure I understand you: is it because you already have an established connection to mongodb from outside levelup and don't want to create new connections? OR is it because you want to control the timing of when the connection to the db is established?

— Reply to this email directly or view it on GitHub https://github.com/watson/mongodown/pull/3#issuecomment-71018322.

watson commented 9 years ago

As far as I recall, a regular node mongodb client normally establishes around 5 connections when it connects to a server and a server running in default configuration is set up to allow 2048 simultaneous connections - so there should be room enough (you can check your server by typing db.serverStatus().connections in the console).

Furthermore the connection object that a client returns differs depending on the client. Mongodown uses the thin wrapper mongojs, but if you use the native mongodb driver these two connection objects will not be compatible - so normally I would not recommend sharing the connection object + the cost of making two is close to nothing.

Being able to set the name of the mongodown collection is a nice feature though :)

watson commented 7 years ago

Closing this due to inactivity. Feel free to reopen 😃