3.2.0 • Published 3 years ago

simple-connection v3.2.0

Weekly downloads
25
License
MIT
Repository
github
Last release
3 years ago

Simple Connection - Node.js Packagebuild status Code Climate

A small implementation to use mongodb with native drives provided by mongodb, but with promises.

Install

npm install simple-connection --save

About config object

Configuration object you can build url connection and the keys username and password are optional. Also you can send a query_params key to build url connection with more mongo parameters.

In example you can found how to send configuration object and how to create a instance to use with simple-connection.

3.x version

To improve performance this version left promises and use more operations and promises from mongodb package. This change make things a little different. Specially at find operation, pay attention when use that and not forget close database after operations.

Another improve is all operations that mongodb package has, simple-connection support.

3.1 version

We made some changes more detail can be found here.

Example

  const DB = require('simple-connection');

  const CONFIG = {
    "protocol": "mongo+srv://", // it's optional, the default will be mongodb://
    "username": process.env.MONGO_USER,
    "password": process.env.MONGO_PASS,
    "server": "127.0.0.1",
    "port": 27017,
    "database_name": "exampleTest"
  };

  const db = new DB(CONFIG);
  const collection = db.open('yourCollection');

  // to insert many pass an array with objects
  collection('insert', { data: 'to insert' })
    .then((success) => {
      console.log(success);
    }).catch((err) => {
      console.log(err);
    });

  // Or if your prefer async/await
  try {
    const result = await collection('insert', ({ data: 'to insert' });
    console.log(result);
  } catch(error)
    console.log(err);
  };

  collection('find', { data: 'to search' })
    .then((dbResources) => {
      dbResources.find.toArray().then((result) => {
        console.log(result);
      }).catch((err) => {
        console.log(err);
      });
    });

  collection('update', { data: 'to search' }, { data: 'to update' })
    .then((success) => {
      console.log(success);
    }).catch((err) => {
      console.log(err);
    });

  collection('remove', { data: 'to remove' }, options)
    .then((success) => {
      console.log(success);
    }).catch((err) => {
      console.log(err);
    });

v4

I've some plans to create a v4 with intents to have types.d.ts and some improvements in perfomance

3.2.0

3 years ago

3.1.5

3 years ago

3.1.4

3 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.11

8 years ago

1.1.10

8 years ago

1.1.9

8 years ago

1.0.6

8 years ago