# mcrud

> Smallest CRUD wrapper over mongodb client with Custom ID generator

Latest version **3.0.0** (published 2023-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install mcrud
pnpm add mcrud
yarn add mcrud
bun add mcrud
```

## 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 | 3.0.0 |
| Published | 2023-04-07 |
| First published | 2021-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 20 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jugnu Agrawal |
| Maintainers | jugnuagrawal |
| Keywords | mongodb, crud, smallest, Custom Id |

## Links

- npm: https://www.npmjs.com/package/mcrud
- Repository: https://github.com/jugnuagrawal/mcrud
- Homepage: https://github.com/jugnuagrawal/mcrud#readme
- Issues: https://github.com/jugnuagrawal/mcrud/issues
- npm.io page: https://npm.io/package/mcrud

## Dependencies (5)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [log4js](https://npm.io/package/log4js.md) ^6.9.1
- [express](https://npm.io/package/express.md) ^4.18.2
- [mongodb](https://npm.io/package/mongodb.md) ^5.2.0
- [render-id](https://npm.io/package/render-id.md) ^1.0.3

## 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

- 3.0.0 (latest) — 2023-04-07
- 2.1.0 — 2022-11-18
- 2.0.3 — 2021-07-30
- 2.0.2 — 2021-07-29
- 2.0.1 — 2021-07-29
- 2.0.0 — 2021-07-28

## README

# mcrud

Smallest CRUD wrapper over mongodb client with Custom ID generator.

## APIs

- count : Get number of records with filter
- list : Get records with filter, select, pagination and sorting
- get : Get record selected fields
- post : Create one or many record with custom ID generation
- put : Update a record with recordId
- delete : Delete a record with recordId
- collection : the MongoDB Collection Object


## Example POST

```javascript
const MCURD = require('mcrud');

const crud = new MCURD({
    collection: 'test',
    database: 'mcrud',
    url: 'mongodb://localhost:27017',
    idPattern: 'TE#####ST##'
});

const payload = {
    firstName: 'John',
    lastName: 'Doe',
    email: 'john@doe.com',
    gender: 'Male'
};

crud.post(payload).then(doc => {
    console.log('document inserted');
    /**
     * Inserted document
     * {
     *     _id:'TE00000ST01',
     *     firstName: 'John',
     *     lastName: 'Doe',
     *     email: 'john@doe.com',
     *     gender: 'Male'
     * }
    */
}).catch(err => {
    console.log(err);
});

//or insert many

const payload = [
    {
        firstName: 'John',
        lastName: 'Doe',
        email: 'john@doe.com',
        gender: 'Male'
    },
    {
        firstName: 'Jane',
        lastName: 'Doe',
        email: 'jane@doe.com',
        gender: 'Female'
    }
];

crud.post(payload).then(docs => {
    console.log('documents inserted');
    /**
     * Inserted documents
     * {
     *     _id:'TE00000ST02',
     *     firstName: 'John',
     *     lastName: 'Doe',
     *     email: 'john@doe.com',
     *     gender: 'Male'
     * }
     * {
     *     _id:'TE00000ST03',
     *     firstName: 'Jane',
     *     lastName: 'Doe',
     *     email: 'jane@doe.com',
     *     gender: 'Female'
     * }
    */
}).catch(err => {
    console.log(err);
});

```


## Example Express Routes

```javascript
const router = require('express').Router();
const MCURD = require('mcrud');

const crud = new MCURD({
    collection: 'test',
    database: 'mcrud',
    url: 'mongodb://localhost:27017',
    idPattern: 'TE#####ST##'
});

router.use(crud.expressRoutes());

// consume
HTTP [GET] /
HTTP [POST] /
HTTP [GET] /:id
HTTP [PUT] /:id
HTTP [DELETE] /:id

```

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