# mongobase

> A lightweight starter template based off the native mongodb driver. Comes with basic CRUD operations and middleware support.

Latest version **1.0.6** (published 2020-03-05) · MIT license · 0 weekly downloads

## Install

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

## 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.6 |
| Published | 2020-03-05 |
| First published | 2020-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Paul Asetre |
| Maintainers | asetr |
| Keywords | mongodb, mongobase, nosql, orm, template, starter, query |

## Links

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

## Dependencies (1)

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

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2020-03-05
- 1.0.5 — 2020-03-05
- 1.0.4 — 2020-03-05
- 1.0.3 — 2020-03-05
- 1.0.2 — 2020-03-05
- 1.0.1 — 2020-03-05
- 1.0.0 — 2020-03-05

## README

# Mongobase
## Overview
A lightweight starter template based off the native mongodb driver. Comes with basic CRUD operations and middleware support.

# Getting started
## Installation
```
npm install mongobase
```
or

```
yarn add mongobase
```

## Basic Usage
```javascript
const mongobase = require('mongobase')

mongobase.init(url, database, options)
mongobase.start()
    .then(() => {
        class UsersModel extends mongobase.Model {
        }
        const collectionName = 'Users'

        const Collection = mongobase.create(collectionName, UsersModel)

        const newUser = { hello: 'world' }

        Colllection.create(newUser)
            .then(doc => {
                console.log(doc)
                //{ hello: 'world', _id: 5e60b3d317e6c15153f0476f }
            })
    })
```

## Advanced Usage
Usage with your own mongo database setup
```javascript
const { MongoClient } = require('mongodb')
const { Model, collection } = require('mongobase')

const collectionName = 'users'
class CustomModel extends Model {
}

const { url, options, db } = configuration
MongoClient.connect(url, options, (err, client) => {
    if(err) return reject(err)

    const database = client.db(db)
    const Collection = collection(collectionName, CustomModel, database)

    const newDocument = { hello: 'fizz', world: 'buzz' }

    Collection
        .create(newDocument)
        .then(doc => {
            console.log(doc)
            //{ hello: 'fizz', world: 'buzz', _id: 5e60b3d317e6c15153f0476f }
        })

})

```

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