0.1.1 • Published 7 years ago

mongodbcrud v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

mongodbcrud

Build Status Coverage Status JavaScript Style Guide

CRUD wrapper around mongodb library

Install

npm i --save mongodbcrud

Usage

const MongoClient = require('mongodb').MongoClient
MongoClient.connect(url)
  .then(db => {
    const mongodbCrud = new MongodbCrud(db)
  })

Api

mongodbCrud.findOne(collectionName, query, options)
mongodbCrud.findOneAndUpdate(collectionName, filter, updateQuery, options)
mongodbCrud.upsertOne(collectionName, filter, updateQuery, options)
mongodbCrud.findOneAndDelete(collectionName, query, options)
mongodbCrud.insertOne(collectionName, doc, options)
mongodbCrud.findAll(collectionName, query)
mongodbCrud.createCollection(collectionName, options)

Each method has the collection name as first parameter. The other parameters follow the mongodb library means.

All methods return promises.

Why

Using mongodb library, some checks should be done anyway. For example Collection.findOne method doesn't throw error if document is not found. This library aims to correct this behaviour without make any logic layer between your code and mongodb library.