Setup
Install via yarn or npm
yarn add gooseberryORnpm install gooseberry
Create a gooseberry config in package.json
Create a data file for each collection you want to seed
Data files can be written in json, yaml, ts or js but must return an array of data.
// seeds/users.json// seeds/posts.json
_Note: if you don't specify an id or id field, gooseberry will assign it a smartID based on collection name and position in array. (e.g. above example will have post1
as its ID)
Gooseberry will recursively transform these into ObjectID
s
// seeds/users.json// seeds/posts.json
Development
This package is new and under active development. PRs are welcome.
Check the 1.0 Roadmap for more.
Methodology
Gooseberry uses placeholder IDs to reference raw seeding data. It makes 2 passes over the data first to setup the initial data and assign IDs and then to replace the placeholder IDs with the real IDs based on your mongoose schemae.
The transformed data is then fed to mongoose.create
as per usual running the validation and methods.
Usage
$ npm install -g gooseberry$ gooseberry COMMANDrunning command...$ gooseberry (-v|--version|version)gooseberry/0.1.7 darwin-x64 node-v12.11.1$ gooseberry --help [COMMAND]USAGE $ gooseberry COMMAND...
Commands
gooseberry help [COMMAND]
display help for gooseberry
USAGE
$ gooseberry help [COMMAND]
ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLI
See code: @oclif/plugin-help
gooseberry seed
describe the command here
USAGE
$ gooseberry seed
OPTIONS
-h, --help show CLI help
-v, --verbose
EXAMPLES
$ gooseberry seed
$ gooseberry seed [collection]
See code: src/commands/seed.ts
Credits
The brilliant idea for the smart IDs comes from seedgoose. Gooseberry builds on that idea and adds mongoose validation et al. to that idea.