scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

Multiple Connections #73

Open karacaenes opened 8 years ago

karacaenes commented 8 years ago

Hi,

Is it possible to use multiple connections to different databases?

What i am trying to do is this:

A desktop nw.js app uses nedb databases. And sends an update request to remote server. Remote server answers with a zip file in case there is an update, otherwise it returns an no update message;

Remote update server is using several different mongodb databses. Say, when clients send an update request to remote server, some clients get updated from database MongoA, some clients are updated from MongoB. Remote server reads some collections from the mongodb, converts them to nedb files, zips them up together with some other resources and sends them to clients. Clients unzip the update then restart.

I think you see where i am going with this.

On remote server I want to connect to MongoA with camo, get my documents, disconnect, connect to a new temporary file based nedb, insert documents, disconnect. zip files.. etc. and then on second request, i want to connect to MongoB and repeat.

I am using same document declarations throught the system. (Both for remote mongo&nedb and client nedb, update zip also sends the latest document declarations js file.)

scottwrobinson commented 8 years ago

I've been planning to add better support for this feature for a while now. Just need to figure out the best way to go about it.

The problem right now is that a global variable is used to get the connected database instance when declaring/using classes. Won't be a hard fix, but it'll take some refactoring.

Thanks!

karacaenes commented 8 years ago

Figured that would be the case. I forked your repo but it would take too may changes across multiple files. I can try if you are up to check such a pull request.