Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-connection

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-connection

Connection using mongo native which desire to be an simple alternative to another communicattions - ES6 ready

  • 3.1.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25
increased by13.64%
Maintainers
1
Weekly downloads
 
Created
Source

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 = {
    "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);
    });

Keywords

FAQs

Package last updated on 24 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc