# bth-mongodb-crud

> Mongodb CRUD

Latest version **1.0.4** (published 2019-06-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install bth-mongodb-crud
pnpm add bth-mongodb-crud
yarn add bth-mongodb-crud
bun add bth-mongodb-crud
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-06-08 |
| First published | 2017-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Peder Tornberg |
| Maintainers | ptorn |
| Keywords | MongoDB |

## Links

- npm: https://www.npmjs.com/package/bth-mongodb-crud
- Repository: https://github.com/ptorn/bth-mongodb-crud
- Homepage: https://github.com/ptorn/bth-mongodb#readme
- Issues: https://github.com/ptorn/bth-mongodb/issues
- npm.io page: https://npm.io/package/bth-mongodb-crud

## Dependencies (1)

- [mongodb](https://npm.io/package/mongodb.md) ^2.2.33

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2019-06-08
- 1.0.3 — 2018-01-07
- 1.0.2 — 2017-12-16
- 1.0.1 — 2017-12-16
- 1.0.0 — 2017-12-16

## README

[![Build Status](https://travis-ci.org/ptorn/bth-mongodb-crud.svg?branch=master)](https://travis-ci.org/ptorn/bth-mongodb-crud)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ptorn/bth-mongodb-crud/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ptorn/bth-mongodb-crud/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/ptorn/bth-mongodb-crud/badges/build.png?b=master)](https://scrutinizer-ci.com/g/ptorn/bth-mongodb-crud/build-status/master)
[![Code Coverage](https://scrutinizer-ci.com/g/ptorn/bth-mongodb-crud/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/ptorn/bth-mongodb-crud/?branch=master)
[![codecov](https://codecov.io/gh/ptorn/bth-mongodb-crud/branch/master/graph/badge.svg)](https://codecov.io/gh/ptorn/bth-mongodb-crud)

BTH-Ramverk2 MongoDB CRUD
=====================

This is a module to handle the basic CRUD methods for a MongoDB database.

## Installation

The port for the database object to communicate to the database is determined  by the environment variable **process.env.DBWEBB_DSN**.
It will default to **mongodb://127.0.0.1:27017/**

1. Installation
`npm install bth-mongodb-crud --save`

2. Initialize
```
const dbObj = require(bth-mongodb-crud)('name of database')
```

3. Usage

#### Create object
```
Ex:
let collection = 'users';
let object = { username: 'John Smith' };

dbObj.insert(collection, object);  // returns a promise

```

#### Delete object
```
dbObj.delete(collection, key, value);

Ex:
let collection = 'users';
let key = '_id';
let value = '1234567';

dbObj.delete(collection, key, value);  // returns a promise
```

#### Update object
```
let collection = 'users';
let key = '_id';
let value = '1234567';

dbObj.update(collection, key, value, {username: 'John Doe'});  // returns a promise
```

#### Find objects
```
let collection = 'users';
let criteria = {};
let projection = {};
let limit = 0; // 0 for getting all objects found.

dbObj.findInCollection(collection, criteria, projection, limit);  // returns a promise
```

## Test

Run tests with mocha, eslint and mongodb in a docker container.

`npm -run docker-mongodb`

`npm run test`

That's it now you are all set.

**Enjoy!**

---
_Source: https://npm.io/package/bth-mongodb-crud · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
