Socket
Socket
Sign inDemoInstall

simple-mongodb

Package Overview
Dependencies
16
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    simple-mongodb

A simple lib to simplify your work of using mongoldb native driver in node.js.


Version published
Maintainers
1
Install size
2.42 MB
Created

Readme

Source

simple-mongodb

CircleCI codecov stable

bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies bitHound Code GPL Licence

A simple lib to simplify your work of using mongoldb native driver in node.js.

Installation

npm install --save simple-mongodb

Usage

First, you should connect the mongodb when app starts:

import DB from 'simple-mongodb';

DB.connect(url);

The connect() method is asynchronous. It will return a Promise, so you can use it like:

DB.connect(url)
  .then(db => {
    // db is the instance of connected database.
  })
  .catch(err => console.log(err));

or:

async function() {
  try {
    const db = await DB.connect(url);    
  } catch (err) {
    console.log(err);
  }
}

Once the mongodb is connected, you could use it anywhere in your code like this:

DB.find(collectionName, args);

The args is an object whose propertoes arr correspond to the MongoDB Driver's arguments.

Methods

.connect(url)

This method must be called before any other methods.

.close(force = false)

Close the db and it's underlying connections.

The force argument is default to false.

.insertOne(name, args)

Inserts a single document into MongoDB.

.insertMany(name, args)

.updateMany(name, args)

.find(name, args)

.findOneAndDelete(name, args)

.findOneAndReplace(name, args)

.findOneAndUpdate(name, args)

.deleteMany(name, args)

.count(name, args = {})

.distinct(name, args)

.createIndex(name, args)

.listCollections(args = {})

.createCollection(args)

Keywords

FAQs

Last updated on 15 Mar 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc