# egg-mongoose-datainit

> egg-mongoose data init

Latest version **1.0.4** (published 2018-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-mongoose-datainit
pnpm add egg-mongoose-datainit
yarn add egg-mongoose-datainit
bun add egg-mongoose-datainit
```

## 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.4 |
| Published | 2018-09-12 |
| First published | 2018-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 0 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | sun |
| Maintainers | ne.fe |
| Keywords | egg, eggPlugin, egg-plugin |

## Links

- npm: https://www.npmjs.com/package/egg-mongoose-datainit
- Repository: https://github.com/eggjs/egg-mongoose-datainit
- Homepage: https://github.com/eggjs/egg-mongoose-datainit#readme
- Issues: https://github.com/eggjs/egg/issues
- npm.io page: https://npm.io/package/egg-mongoose-datainit

## Recent versions

- 1.0.4 (latest) — 2018-09-12
- 1.0.3 — 2018-09-11
- 1.0.2 — 2018-09-05
- 1.0.1 — 2018-09-05
- 1.0.0 — 2018-09-04

## README

# egg-mongoose-datainit

基于egg-mongoose的初始化数据导入插件，发布在公司私有npm仓库中，

## 安装

```bash
$ npm i egg-mongoose-datainit
```

## 使用

1、在config/plugin.js 中声明：
```js
module.exports = {
  'mongoose-datainit': {
    enable: true,
    package: 'egg-mongoose-datainit',
  },
};
```



2、准备需要导入的数据：即 data/modelName.json
      将需要导入的数据以数组格式置于.json文件中，再将.json文件放于项目根目录下的data文件夹中；其中json文件命名必须与model数据模型的modelName一致；



3、导入方式：insert、upsert、drop；在config.{env}.js里面做配置

   ```js
'mongoose-datainit': {
    modelName: 'drop',  // upsert、drop
}
   ```
- 插入insert：默认导入方式，可不做配置；即如果没有有该条数据，则插入该条数据，
- 更新插入upsert：即如果有该条数据，则修改该条数据的值，没有则插入
- 重置drop：即重置集合所有数据


## 说明：

- egg-mongoose-datainit基于egg-mongoose，故在使用请确保egg-mongoose的所有配置皆已完善
- egg-mongoose-datainit能够导入的前提为该集合的model已存在，并且data文件夹下有对应的json文件

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