# salak-mongo

> mongoose for salak

Latest version **1.0.1** (published 2018-01-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install salak-mongo
pnpm add salak-mongo
yarn add salak-mongo
bun add salak-mongo
```

## 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.1 |
| Published | 2018-01-30 |
| First published | 2018-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+11 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | wengeek |
| Maintainers | wengeek |
| Keywords | salak, mongoose |

## Links

- npm: https://www.npmjs.com/package/salak-mongo
- Repository: https://github.com/SalakJS/salak-mongo
- Homepage: https://github.com/SalakJS/salak-mongo#readme
- Issues: https://github.com/SalakJS/salak-mongo/issues
- npm.io page: https://npm.io/package/salak-mongo

## Dependencies (2)

- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1
- [mongoose](https://npm.io/package/mongoose.md) ^4.13.7

## 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
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-01-30
- 2.0.0-beta.10 (next) — 2019-05-13
- 2.0.0-beta.9 — 2019-05-10
- 2.0.0-beta.8 — 2019-05-10
- 2.0.0-beta.7 — 2019-05-10
- 2.0.0-beta.6 — 2019-02-25
- 2.0.0-beta.5 — 2019-02-25
- 2.0.0-beta.4 — 2018-10-17
- 2.0.0-beta.3 — 2018-10-11
- 2.0.0-beta.2 — 2018-07-26
- 2.0.0-beta.1 — 2018-07-25
- 2.0.0-beta — 2018-07-23
- 1.0.0 — 2018-01-03

## README

# salak-mongo

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![David deps][david-image]][david-url]
[![NPM download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/salak-mongo.svg?style=flat-square
[npm-url]: https://npmjs.org/package/salak-mongo
[travis-image]: https://img.shields.io/travis/SalakJS/salak-mongo.svg?style=flat-square
[travis-url]: https://travis-ci.org/SalakJS/salak-mongo
[david-image]: https://img.shields.io/david/SalakJS/salak-mongo.svg?style=flat-square
[david-url]: https://david-dm.org/SalakJS/salak-mongo
[download-image]: https://img.shields.io/npm/dm/salak-mongo.svg?style=flat-square
[download-url]: https://npmjs.org/package/salak-mongo

Mongoose for SalakJS.

## Install

```sh
$ npm install --save salak-mongo
```

## Usage

### Config

In middleware:

```javascript
module.exports = {
  middleware: [
    {
      name: 'mongo',
      package: require('salak-mongo')
    }
  ],
  mongo: {
    uri: 'mongodb://localhost:27017/yourdb'
  }
}
```

### Model

Salak will autoload the model directory from all modules.

Such as common/model/user.js:

```javascript
const { mongoose } = require('salak-mongo')
const Schema = mongoose.Schema

const User = new Schema({
  username: {
    type: String,
    unique: true
  }
})

module.exports = mongoose.model('User', User, 'User')
```

### Use in Service or Controller

common/service/user.js

```javascript
const { Service } = require('salak')

class User extends Service {
  async createUser (username) {
    const user = await this.model('user').create({
      username
    })

    return user
  }
}

module.exports = User
```

## API

### mongoose

Ref to [mongoose](https://github.com/Automattic/mongoose)

### BaseContext.prototype.model(name, module)

The function which register on BaseContext

- name: model filename
- module: the model located in, default: the current module

@return model

## License

MIT

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