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

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Simple Connection - build 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

Configurantion object the you can build connection url the keys username and password are optional. Also you can send a query_params key to build connection url with more mongo parameters. In example you can found how to send configuration object and how to create instantion to use with simple-connection.

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((success) => {
    console.log(success);
  }).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 27 Jan 2019

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