Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/allevo/mongodbcrud
CRUD wrapper around mongodb library
https://github.com/allevo/mongodbcrud
Last synced: 14 days ago
JSON representation
CRUD wrapper around mongodb library
- Host: GitHub
- URL: https://github.com/allevo/mongodbcrud
- Owner: allevo
- License: mit
- Created: 2017-08-04T20:21:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-05T09:10:29.000Z (over 7 years ago)
- Last Synced: 2024-09-23T02:18:33.665Z (about 2 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongodbcrud
[![Build Status](https://travis-ci.org/allevo/mongodbcrud.svg?branch=master)](https://travis-ci.org/allevo/mongodbcrud)
[![Coverage Status](https://coveralls.io/repos/github/allevo/mongodbcrud/badge.svg?branch=master)](https://coveralls.io/github/allevo/mongodbcrud?branch=master)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)CRUD wrapper around mongodb library
## Install
```sh
npm i --save mongodbcrud
```## Usage
```js
const MongoClient = require('mongodb').MongoClient
MongoClient.connect(url)
.then(db => {
const mongodbCrud = new MongodbCrud(db)
})
```## Api
```js
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.