1.1.1 • Published 7 years ago

simple-mongodb v1.1.1

Weekly downloads
6
License
GPL-3.0
Repository
github
Last release
7 years ago

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)

1.1.1

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago