# mdb-driver

> async await mongodb driver

Latest version **0.0.4** (published 2020-09-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install mdb-driver
pnpm add mdb-driver
yarn add mdb-driver
bun add mdb-driver
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2020-09-14 |
| First published | 2020-09-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Andrey Sukhodeev |
| Maintainers | gravitymir |
| Keywords | mongodb, async, await, database |

## Links

- npm: https://www.npmjs.com/package/mdb-driver
- Repository: https://github.com/gravitymir/mdb-driver
- Homepage: https://github.com/gravitymir/mdb-driver#readme
- Issues: https://github.com/gravitymir/mdb-driver/issues
- npm.io page: https://npm.io/package/mdb-driver

## Dependencies (1)

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

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

- 0.0.4 (latest) — 2020-09-14
- 0.0.3 — 2020-09-14
- 0.0.2 — 2020-09-14
- 0.0.1 — 2020-09-14

## README

# mdb-driver

Node.js npm package for works with mongodb driver >= 4.2 version

## install

``` js
npm i mdb-driver
```

## use

### listDatabases

``` js
const Mdb = require('mdb-driver');
const db = new Mdb('mongodb://localhost:27017');

(async () => {
    let dbs = db.listDatabases();
    console.log(await dbs);
})();
```

### listCollections

``` js
let listCollections = db.listCollections('db_name');

(async () => {
    console.log(await listCollections);
})();
```
### findOne

``` js
let findOneResult = db.findOne({
    dbName: 'test',
    collection: 'users',
    query: {
        title: "Username"
    },
    options: {
        sort: {
            age: -1
        },
        projection: {
            _id: 0,
            age: 1,
            phone: 1
        },
    }
});

(async () => {
    console.log(await findOneResult);
})();
```

### find
``` js
let resultArray = db.find({
    dbName: 'test',
    collection: 'users',
    query: {
        age: {
            $lt: 15
        }
    },
    options: {
        sort: {
            name: 1
        },
        projection: {
            _id: 0,
            name: 1,
            phone: 1
        },
    }
});

(async () => {
    console.log(await resultArray);
})();
```

### insertOne
``` js
let insertOneResult = db.insertOne({
    dbName: 'test',
    collection: 'users',
    document: {
        {
            name: 'Bob',
            age: 31,
            phone: 6500000000
        }
    }
})
```

### insertMany
``` js
let insertMany = db.insertMany({
    dbName: 'test',
    collection: 'users',
    documents: [{
            name: 'Nikoly',
            age: 27,
            phone: 6500000009
        },
        {
            name: 'Mark',
            age: 55,
            phone: 6500000007
        },
        {
            name: 'Givi',
            age: 62,
            phone: 6500000005
        }
    ],
    options: {
        ordered: true
    }
})
```

### updateOne
``` js
let updateOneResult = db.updateOne({
    dbName: 'test',
    collection: 'users',
    filter: {
        name: 'Givi'
    },
    update: {
        $set: {
            age: 63
        }
    },
    options: {
        // this option instructs the method to create a document if no documents match the filter
        upsert: false
    }
})
```

### updateMany
``` js
let updateManyResult = db.updateMany({
    dbName: 'test',
    collection: 'users',
    filter: {
        birthday: toDay
    },
    update: {
        $inc: { //https://docs.mongodb.com/manual/reference/operator/update-field/
            age: 1
        }
    }
})
```

### replaceOne
``` js
let replaceOneResult = db.replaceOne({
    dbName: 'test',
    collection: 'users',
    query: {
        name: 'Bob'
    },
    replacement: {
        phone: 7500000000
    },
    options: {
        // create a document if no documents match the query
        upsert: true,
    }
})
```

### deleteOne
``` js
let deleteOneResult = db.deleteOne({
    dbName: 'test',
    collection: 'users',
    query: {
        phone: {
            $type: "string"
        }
    }
})
```

### deleteMany
``` js
let deleteManyResult = db.deleteMany({
    dbName: 'test',
    collection: 'users',
    query: {
        age: {
            $gte: 80 //https://docs.mongodb.com/manual/reference/operator/query-comparison/
        }
    }
})
```

### other
``` js
let res;
res = estimatedDocumentCount({
    dbName: 'test',
    collection: 'users'
});

res = countDocuments({
    dbName: 'test',
    collection: 'users',
    query: {
        age: {
            $in: [18, 65]
        }
    }
});

db.distinct({//https://docs.mongodb.com/drivers/node/usage-examples/distinct
    dbName,
    collection,
    field,
    query
})
```

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