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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@superseed/mongoose

v3.0.7

Published

A super-seed module that allows support for MockGenerators using [mongoose](https://www.npmjs.com/package/mongoose) schema

Downloads

119

Readme

@superseed/mongoose

A super-seed module that allows support for MockGenerators using mongoose schema

Install

npm install @superseed/mongoose

Usage

Example:

const { Schema } = require('mongoose');
const { Seeder, SeedJob } = require('@superseed/superseed');
const MongooseMockGenerator = require('@superseed/mongoose');
const { DataSource } = require('@superseed/core');

const ObjectId = Schema.Types.ObjectId;

class CustomSeeder extends DataSource {
  createSeeds(seeds) {
    return seeds; // ideally should save data and return values saved 
  }
}

const personSchema = {
  id: ObjectId,
  firstName: {
    type: String,
    required: true,
    lowercase: true,
    trim: true
  },
  lastName: {
    type: String,
    required: true,
    lowercase: true,
    trim: true
  },
  email: {
    type: String
  },
  birth_date: {
    type: Date
  },
  gender: {
    type: String,
    enum: ['Male', 'Female']
  }
};

const catSchema = {
  id: ObjectId,
  name: {
    type: String,
    required: true,
    lowercase: true,
    trim: true
  },
  fullName: String,
  ownerId: ObjectId
};

const options = {
  _id: { skip: true },
  email: { generator: 'email' }
};

const catOptions = {
  ownerId: {
    generator: 'hasOne',
    target: 'users',
    foreignField:'id'
  },
  fullName: {
    generator:  (db, object) => {
      const {lastName} = db.users.find(({id}) => id === object.ownerId);
      return `${object.name} ${lastName}`
    }
  }
};

const personSeedJob = new SeedJob(
  'users',
  new MongooseMockGenerator(new Schema(personSchema), options),
  new CustomSeeder()
);

const catSeedJob = new SeedJob(
  'cats',
  new MongooseMockGenerator(new Schema(catSchema), catOptions),
  new CustomSeeder()
);

const seeder = new Seeder();
seeder.addJob(personSeedJob, {count: 1})
  .addJob(catSeedJob, {count: 2});
seeder.seed().then(data => {
  console.log(data);
});

Sample Data

{
  "users":[
    {
      "id":"5d595690aa924497bb891281",
      "firstName":"blkwcs$5s%",
      "lastName":"gkwd0xh7fncad^h",
      "email":"[email protected]",
      "birth_date":"2019-08-18T13:45:52.474Z",
      "gender":"Female"
    }
  ],
  "cats":[
    {
      "id":"5d595690aa924497bb891282",
      "name":"qf[*ek%",
      "ownerId":"5d595690aa924497bb891281",
      "_id":"5d595690aa924497bb891283",
      "fullName":"qf[*ek% gkwd0xh7fncad^h"
    },
    {
      "id":"5d595690aa924497bb891284",
      "name":"jf3inmgp",
      "ownerId":"5d595690aa924497bb891281",
      "_id":"5d595690aa924497bb891285",
      "fullName":"jf3inmgp gkwd0xh7fncad^h"
    }
  ]
}

Documentation

Methods

constructor(ModelName, mongooseSchema, options)

  • ModelName: Used when a creating a mongoose model.

  • mongooseSchema: A mongoose schema

  • Generation options per field. Where key is the field name and value is an object.

    • options.<fieldName>.skip : When set to true would skip the field. No data would be generated for this field.

    • options.<fieldName>.generator <String> or <function>. The following generators are supported:

      • hasOne:

        • target: target entity
        • foreignField: target field
      • hasMany:

        • target: target entity
        • foreignField: target field
        • unique: If the target entity must be unique
        • min: Minimum number of entities
        • max: Minimum number of entities
        • amount: a fixed
      • email: Would generate an email.

      • A function: a function that receives as arguments

        • db: all the seeds created grouped by type
        • object: the current mock object being populated with values Another way to access these values is via this.db and this.object. Not that accessing via this would not work for arrow functions.

generateMock(db, staticField)

  • db <Object> A plain object where a key is the entity key and value is an array of entities. Is used
  • staticFields <Object> used to define that do not need dynamic data. The provided values would be used.

Mongoose versions

| Version | Supported | | ------- | ------------------ | | 5.x | :white_check_mark: | | 4.x | :white_check_mark: |