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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mongeese-cli

v1.0.15

Published

Auto-generate MongoDB migration scripts by detecting changes in your Mongoose schemas.

Readme

🧬 Mongeese CLI

Auto-generate MongoDB migration scripts by detecting changes in your Mongoose schemas.

Mongeese CLI is a CLI tool that tracks your Mongoose models, detects schema changes, and generates versioned MongoDB migration files — just like TypeORM or Prisma, but built for MongoDB's schemaless world.


📦 Installation

Install globally with npm:

npm install -g mongeese-cli

Or with yarn:

yarn global add mongeese-cli

Or use npx (no install required):

npx mongeese-cli <command>

⚡ Quick Start

npx mongeese-cli init                   # Sets up migration tracking
npx mongeese-cli generate               # Detects changes and generates migration
npx mongeese-cli migrate up             # Applies pending migrations
npx mongeese-cli migrate status         # Shows migration status

🛠 Commands

mongeese init

Initialize Mongeese in your project. This creates a connection configuration file.

mongeese init

mongeese generate [options]

Generate a migration file by comparing your current Mongoose schemas with the database state.

mongeese generate                           # Auto-generate migration
mongeese generate --name add_user_fields    # Generate with custom name
mongeese generate -n create_indexes         # Short form

Options:

  • -n, --name <name> - Custom name for the migration file

mongeese migrate [direction] [options]

Apply, rollback, or show status of migrations.

mongeese migrate                            # Show migration status (default)
mongeese migrate status                     # Show migration status
mongeese migrate up                         # Apply all pending migrations
mongeese migrate down                       # Rollback last migration
mongeese migrate down --target 20240501_120000_add_users  # Rollback to specific migration

Options:

  • -t, --target <target> - Target migration filename or timestamp

🧠 Why Use Mongeese CLI?

Eliminate manual migration scripts - Auto-generate migrations from schema changes

🛡 Prevent silent schema drift - Track all changes between code and database

🚀 Speed up development - Works seamlessly with NestJS and Mongoose projects

🔁 Safe rollbacks - Generate both up and down migration commands

🧩 CI/CD friendly - Version-controlled migration files for deployment pipelines


📋 How It Works

  1. Initialize: Run mongeese init to set up your database connection
  2. Develop: Make changes to your Mongoose schemas as usual
  3. Generate: Run mongeese generate to create a migration file
  4. Review: Check the generated migration commands
  5. Apply: Run mongeese migrate up to execute the migration
  6. Deploy: Commit migration files and run in other environments

The CLI compares your current Mongoose model definitions with the actual database structure to detect changes, then generates appropriate MongoDB commands to sync them.


🔧 Configuration

After running mongeese init, edit the generated connection file:

TypeScript projects:

// mongeese.connection.ts
export async function getDbWithClient(dbName?: string): Promise<DbWithClient> {
  const client = new MongoClient(process.env.MONGODB_URI);
  await client.connect();
  const db = client.db(dbName);
  (db as DbWithClient).client = client;
  return db as DbWithClient;
}

JavaScript projects:

// mongeese.connection.js
export async function getDbWithClient(dbName) {
  const client = new MongoClient(process.env.MONGODB_URI);
  await client.connect();
  const db = client.db(dbName);
  db.client = client;
  return db;
}

Make sure to set your MONGODB_URI environment variable.


🛠 Requirements

  • Node.js >= 16
  • Mongoose >= 7
  • MongoDB connection
  • Works great with NestJS, but framework-agnostic

📝 Example Workflow

# 1. Initialize in your project (add your Mongo Connection URI)
mongeese init

# 2. Make changes to your Mongoose schemas
# (add fields, modify types, create new models, etc.)

# 3. Generate migration
mongeese generate --name add_user_preferences

# 4. Review the generated migration file
# migrations/20240825_143022_add_user_preferences.js

# 5. Apply the migration
mongeese migrate up

# 6. Check status
mongeese migrate status

⚠️ Important Notes

  • Always review generated migrations before applying them
  • Test migrations in a development environment first
  • Keep migration files in version control
  • Mongeese compares live database state with your code, so ensure your database is accessible
  • The tool works by analyzing both your Mongoose model files and current database collections

🤝 Contributing

We welcome issues, feedback, and PRs!

See CONTRIBUTING.md for how to get started.


📄 License

MIT License