npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gooseberry

v0.1.7

Published

Mongoose seeder with smart IDs and validation

Downloads

5

Readme

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.