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

@videsk/mongoose-dummy

v1.6.0

Published

Random data generator based on mongoose schema, with very flexible options, populate feature and easily integrable with random data generators libraries.

Readme

🎲 Mongoose Dummy

Create realistic test data for your Mongoose models with zero hassle!

npm version License: LGPL-2.1

Mongoose Dummy is a powerful random data generator built specifically for Mongoose schemas. Generate realistic test data with support for complex relationships, nested objects, and custom generators. Perfect for testing, development, and seeding your MongoDB databases.

✨ Features

  • 🔌 Seamless integration with Mongoose models
  • 🔄 Smart population of referenced models
  • 📋 Random selection from enum values
  • 🎯 Customizable field filters
  • 🔧 Flexible array length control
  • 🎨 Works with Faker.js and other data generation libraries
  • 📦 Support for nested objects and arrays
  • 🧪 Perfect for testing and development

📦 Installation

npm install @videsk/mongoose-dummy

🚀 Quick Start

import mongoose from 'mongoose';
import MongooseDummy from '@videsk/mongoose-dummy';
import { faker } from '@faker-js/faker';

// Initialize with mongoose
const dummy = new MongooseDummy(mongoose);

// Add faker.js support
dummy.generators = { faker };

// Generate fake data
const fakeUser = dummy.model('User').generate();

📖 Usage Guide

🏗️ Defining Schemas

Add the dummy property to any field you want to generate data for:

const userSchema = new mongoose.Schema({
  name: {
    type: String,
    dummy: ({ faker }) => faker.person.fullName()
  },
  email: {
    type: String,
    dummy: ({ faker }) => faker.internet.email()
  },
  address: {
    street: {
      type: String,
      dummy: ({ faker }) => faker.location.streetAddress()
    },
    city: {
      type: String,
      dummy: ({ faker }) => faker.location.city()
    }
  },
  createdAt: {
    type: Date,
    dummy: ({ faker }) => faker.date.past()
  }
});

🔄 Working with References

Automatically populate referenced models:

const orderSchema = new mongoose.Schema({
  customer: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    populate: true,  // 👈 Will generate full user data
    dummy: true
  },
  products: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Product',
    populate: true,
    dummy: true
  }],
  total: {
    type: Number,
    dummy: ({ faker }) => faker.number.float({ min: 10, max: 1000 })
  }
});

📝 Smart Enum Handling

const taskSchema = new mongoose.Schema({
  status: {
    type: String,
    enum: ['pending', 'in-progress', 'completed'],
    dummy: true  // 👈 Will randomly select from enum values
  },
  priority: {
    type: String,
    enum: ['low', 'medium', 'high'],
    dummy: true
  }
});

🎯 Custom Field Filters

Generate data only for specific fields:

// Replace default filter
dummy.defaultFilter = options => options.customKey;

// Only generate required fields
const requiredOnly = dummy.model('User').generate(
  options => options.required === true
);

// Only generate fields with specific validators
const validatedFields = dummy.model('User').generate(
  options => options.validate !== undefined
);

📚 Array Configuration

Control the length of generated arrays:

// Global array length setting
const dummy = new MongooseDummy(mongoose);
dummy.setup({ arrayLength: 5 });

// Generate data with custom array length
const data = dummy.model('Order').generate();
// All arrays will have 5 items

🔗 Complex Relationships

Generate data with nested relationships and dependencies:

const companySchema = new mongoose.Schema({
  name: {
    type: String,
    dummy: ({ faker }) => faker.company.name()
  },
  employees: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    populate: true,
    dummy: true
  }],
  departments: [{
    name: {
      type: String,
      dummy: ({ faker }) => faker.commerce.department()
    },
    manager: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'User',
      populate: true,
      dummy: true
    },
    budget: {
      type: Number,
      dummy: ({ faker }) => faker.number.int({ min: 10000, max: 1000000 })
    }
  }]
});

🎨 Custom Data Generation

Use values from other fields in your generators:

const productSchema = new mongoose.Schema({
  name: {
    type: String,
    dummy: ({ faker }) => faker.commerce.productName()
  },
  basePrice: {
    type: Number,
    dummy: ({ faker }) => faker.number.float({ min: 10, max: 1000 })
  },
  discountedPrice: {
    type: Number,
    dummy() {
      return this.basePrice * 0.8; // Access other generated fields
    }
  }
});

⚠️ Limitations

  • 🔄 Populate feature is limited to one level deep to prevent circular dependencies
  • 🏷️ Fields without a dummy key are ignored in generation
  • 🔒 Some Mongoose features like virtual fields are not supported

🤝 Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

🧪 Running Tests

npm test

📄 License

LGPL-2.1 License - Created with ❤️ by Videsk™

🙏 Acknowledgments

Special thanks to all contributors and the Mongoose community for making this project possible!