https://github.com/tmigone/mongooseeder
mongodb seeder using mongoose schemas
https://github.com/tmigone/mongooseeder
Last synced: 29 days ago
JSON representation
mongodb seeder using mongoose schemas
- Host: GitHub
- URL: https://github.com/tmigone/mongooseeder
- Owner: tmigone
- Created: 2018-06-15T13:33:00.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-15T15:36:46.000Z (almost 7 years ago)
- Last Synced: 2025-03-13T21:18:47.623Z (about 2 months ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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.Schemalet 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"
}
]
}
```