# db-helper-meetin

> help to use mongodb

Latest version **1.1.4** (published 2017-10-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install db-helper-meetin
pnpm add db-helper-meetin
yarn add db-helper-meetin
bun add db-helper-meetin
```

## 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.1.4 |
| Published | 2017-10-20 |
| First published | 2017-08-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| Author | Nate |
| Maintainers | natekong |
| Keywords | mongodb |

## Links

- npm: https://www.npmjs.com/package/db-helper-meetin
- Repository: https://github.com/meetinco/DBHelper
- Homepage: https://github.com/meetinco/DBHelper#readme
- Issues: https://github.com/meetinco/DBHelper/issues
- npm.io page: https://npm.io/package/db-helper-meetin

## Dependencies (3)

- [bluebird](https://npm.io/package/bluebird.md) ^3.5.0
- [mongoose](https://npm.io/package/mongoose.md) ^4.11.7
- [merror-meetin](https://npm.io/package/merror-meetin.md) ^1.1.3

## Recent versions

- 1.1.4 (latest) — 2017-10-20
- 1.1.3 — 2017-09-27
- 1.1.2 — 2017-09-21
- 1.1.1 — 2017-09-20
- 1.1.0 — 2017-09-15
- 1.0.0 — 2017-08-16

## README

# Usage

### app.js 
init db
```javascript
const connectHelper = require('db-helper').connectHelper;
const dbAddress = '';
const debugMode = true;

connectHelper.initDB(dbAddress, debugMode);
```

### db/model.js
custom db model
```javascript
const DBModel = require('db-helper').DBModel;
const schema = require('./schema'); // You have to create a schema.js. See below.

class PersonModel extends DBModel {
    constructor() {
        const dbName = 'person';
        super(dbName, schema);
    }
} 
module.exports = new PersonModel();
```

### db/schema.js
define your schema
```javascript
const mongoose = require('mongoose');

// 数据版本号，数据更新时需要更新版本号
exports.DATA_VERSION = 1;

const personShema = new mongoose.Schema({

    personId: String,
    name: String,
    nickname: String,
    avatar: String,
    gender: Number,
    wxOpenid: String,
    personTypes: Array,
    phone: String,
    waiterInfos: [{
        number: Number,
        shopId: String,
        working: Boolean,
        tables: [{
            tableId: String,
            name: String,
            tableIndex: Number
        }]
    }],

    dataVersion: {type: Number, default: exports.DATA_VERSION}, // 数据版本号
});
// 增加创建和修改日期字段
personShema.set('timestamps', true);

module.exports = personShema;
```
### manage.js
try to use it
```javascript
const personModel = require('./db/model');
personModel.newDoc({name: 'just a test'})
```

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