mongoose-data-seed
Seed mongodb with data using mongoose models
Install
npm install --save mongoose-data-seedmd-seed init
md-seed init
will ask you to choose a folder for your seeders.
md-seed init
will create the seeders
folder, generate md-seed-config.js
and update your package.json
.
Use
Generate seeder file
md-seed g users
Run all seeders
md-seed run
Or run specific seeders
md-seed run users posts comments
Options
Drop the database before seeding
md-seed run --dropdb
Seeder Example
;; const data = email: 'user1@gmail.com' password: '123123' passwordConfirmation: '123123' isAdmin: true email: 'user2@gmail.com' password: '123123' passwordConfirmation: '123123' isAdmin: false ; async { return User ; } async { return User; } ;
md-seed-config.js
md-seed
expecting to get 3 values from md-seed-config.js
seedersList
- A key/value list of all your seeders,md-seed
will run your seeders as they ordered in the list.connect
- Connect to mongodb implementation (should return promise).dropdb
- Drop/Clear the database implementation (should return promise).
Example
; ;;; const mongoURL = processenvMONGO_URL || 'mongodb://localhost:27017/dbname'; /** * Seeders List * order is important * @type */const seedersList = Users Posts Comments;/** * Connect to mongodb implementation * @return */const connect = async await mongoose;/** * Drop/Clear the database implementation * @return */const dropdb = async mongooseconnectiondb;
Configurations
mongoose-data-seed
configurations will get loaded from the mdSeed
field in your package.json
file.
Field | Default Value | Description |
---|---|---|
seedersFolder |
'./seeders' |
Path for your seeders-folder, seeders will be generated into this folder. |
customSeederTemplate |
undefined |
Path to a custom template file to generate your seeders from. |
Examples
License
MIT