🥂 simple-connection 3.1 🍾

This blog post is to give more detail about some changes at version 3.1.

Simple-connection born due MongoDB package early versions don't support native promises back in 2016 when Node 4 goes alive, also the objective are simplify connection with MongoDB.

Time goes fast in our industry and after a really long time without a update version 3.0 come alive, with a really break change, the whole implementation with promises goes out from library and relying completely in solution from MongoDB package and focus only in manage connectinos.

But a bug goes to production without I notice that. I'm really sorry about that mistake. Here I want to explain more about the fix and how that change the usage for version 3.1.

First the close connection after make consulting in Database was removed, people need control it by our own. It's a mistake want to control that, and cause more bugs.

Multiple collections

A problem I notice was the use only a unique collection per connection, and when we need consult another collection, causes a conflict with connection and consulting make that impossible and to make this possible was made a major change that I rotulate the version 3.1

Now when use method open with collectionName you are able to use operation normally. But now a collectionwas made available and return a which return a operation to use, and can be called to open another collections instead to open a new connection.

Follow the example usage. Also see unit tests to get more examples

const CONFIG = {
  "server": "localhost",
  "port": 27017,
  "database_name": "mydb_test"
};

/** THE OLD WAY **/

const db = new DB(CONFIG); // makes connection with db
const collection = db.open('exampleCollection'); // open a collection
collection('insert', { name: 'filipe silva' }) // make insert

/** THE NEW WAY **/
const db = new DB(CONFIG); // makes connection with db
const collection = db.collection('exampleCollection'); // open a collection
collection('insert', { name: 'filipe silva' }) // make insert

How you can see in the example theres not a big change, only the methods name, open method is a little bit slower than collection method.  

The big change

There is a but, the main effort was don't break change I believe that is achieved, but we don't return object db in findoperation, that occur due we don't open and close db after operations. Which is more align with mongo good pratices.

That version use a more modern and secure version from mongodb.

Any suggestion, issue, comment or contribution are welcome, follow simple-connection in Github.