🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

simple-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

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.

1.1.1
latest
Source
npm
Version published
Weekly downloads
6
500%
Maintainers
1
Weekly downloads
 
Created
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

mongodb

FAQs

Package last updated on 15 Mar 2017

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