# @tmigone/mongooseeder

> mongodb seeder using mongoose models

Latest version **1.0.2** (published 2018-06-15) · WTFPL license · 0 weekly downloads

## Install

```sh
npm install @tmigone/mongooseeder
pnpm add @tmigone/mongooseeder
yarn add @tmigone/mongooseeder
bun add @tmigone/mongooseeder
```

## 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.2 |
| Published | 2018-06-15 |
| First published | 2018-06-15 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tomás Migone |
| Maintainers | tmigone |
| Keywords | MongoDB, mongoose, seeder, seed, data, json |

## Links

- npm: https://www.npmjs.com/package/@tmigone/mongooseeder
- Repository: https://github.com/tomasmigone/mongooseeder
- Homepage: https://github.com/tomasmigone/mongooseeder#readme
- Issues: https://github.com/tomasmigone/mongooseeder/issues
- npm.io page: https://npm.io/package/@tmigone/mongooseeder

## Dependencies (4)

- [fs](https://npm.io/package/fs.md) 0.0.1-security
- [path](https://npm.io/package/path.md) ^0.12.7
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1
- [mongoose](https://npm.io/package/mongoose.md) ^5.1.5

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2018-06-15
- 1.0.1 — 2018-06-15
- 1.0.0 — 2018-06-15

## README

# mongooseeder
Seed a mongodb database with data taken from JSON files, for testing purposes or just populating your database.
Library requires usage of mongoose models.

## Installation

```bash
npm install --save @tmigone/mongooseeder
```

## Usage
```javascript
let uri = ''

let data = [{
  name: 'Author',
  model: path.join(__dirname, './models/Author.js'),
  migration: path.join(__dirname, './migrations/authors.json'),
  drop: true
}]

let seeder = new MongooSeeder(uri, data)
seeder.seed()

```

## Options
| Option  | Description |
| ------------- | ------------- |
| name  | Model name. Must be same as the registered shema on mongoose.  |
| model  | Path to mongoose model file.  |
| migration  | Path to seeder input data.  |
| drop  | ```true:false``` Whether to drop the collection before importing or not.  |

## Model schema
```javascript
const mongoose = require('mongoose')
let Schema = mongoose.Schema

let AuthorSchema = new Schema({
  first_name: {type: String, required: true, max: 100},
  family_name: {type: String, required: true, max: 100}
})

module.exports = mongoose.model('Author', AuthorSchema)
```

## Migration file
```json
{
  "model": "Author",
  "documents": [
    {
      "first_name": "John",
      "family_name": "Doe"
    },
    {
      "first_name": "Jane",
      "family_name": "Smith"
    },
    {
      "first_name": "Edgar",
      "family_name": "Poe"
    }
  ]
}
```

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