gooseberry
Mongoose seeder with smart IDs and validation
Last updated 7 months ago by hennessyevan .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install gooseberry 
SYNC missed versions from official npm registry.

oclif Version Downloads/week License

Setup

Install via yarn or npm

yarn add gooseberry
OR
npm install gooseberry

Create a gooseberry config in package.json

{
  //...,
  "gooseberry": {
    "modelDir": "path/to/mongooseModels",
    "mongoURI": "mongodb://localhost:27017/{TARGET_DB_NAME}",
    "dataDir": "path/to/seedData",
    "dropDatabase": true (optional)
  }
}

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
[{
  "_id": "Jane",
  "firstName": "Jane",
  "lastName": "Doe"
}]
// seeds/posts.json
[{
  "title": "My new post",
  "author": "Jane" // use _id from seeded user
}]

_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 ObjectIDs

// seeds/users.json
[{
  "_id": ObjectID("5d6e80622037da89a22195f7"),
  "firstName": "Jane",
  "lastName": "Doe"
}]
// seeds/posts.json
[{
  "_id": ObjectID("5d6e80622037da89a22195f8"),
  "title": "My new post",
  "author": ObjectID("5d6e80622037da89a22195f7")
}]

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 COMMAND
running 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.

Current Tags

  • 0.1.7                                ...           latest (7 months ago)

14 Versions

  • 0.1.7                                ...           7 months ago
  • 0.1.6                                ...           9 months ago
  • 0.1.5                                ...           9 months ago
  • 0.1.4                                ...           9 months ago
  • 0.1.3                                ...           9 months ago
  • 0.1.2                                ...           9 months ago
  • 0.1.1                                ...           9 months ago
  • 0.1.0                                ...           9 months ago
  • 0.0.6                                ...           9 months ago
  • 0.0.5                                ...           9 months ago
  • 0.0.4                                ...           9 months ago
  • 0.0.3                                ...           9 months ago
  • 0.0.2                                ...           9 months ago
  • 0.0.1                                ...           9 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (17)
Dev Dependencies (16)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |