@alieutech/seedsmith
v0.1.2
Published
CLI + library to auto-generate MongoDB seed data from Mongoose schemas
Maintainers
Readme
SeedSmith
A Node.js + TypeScript CLI and library that auto-generates MongoDB seed data from Mongoose schemas.
Features
- Uses
@faker-js/fakerto generate realistic values - Inspects Mongoose schemas automatically
- Handles refs by linking to existing docs or creating stubs
- Prevents seeding when
NODE_ENV=production
Install
npm installBuild
npm run buildCLI usage
# Basic
seedsmith --uri mongodb://localhost:27017/mydb --models ./path/to/models --count 25
# Quick start with your Atlas cluster (use environment variable – do NOT hardcode secrets)
export MONGO_URI="mongodb+srv://<username>:<password>@<cluster-host>/<dbName>?retryWrites=true&w=majority&appName=SeedSmith"
NODE_ENV=development \
seedsmith \
--uri "$MONGO_URI" \
--models ./models \
--count 25Include/Exclude models
seedsmith --uri mongodb://localhost:27017/mydb --models ./models --include User,Post --exclude Log
Drop collections before seeding
seedsmith --uri mongodb://localhost:27017/mydb --models ./models --drop
### Optional config file
Create `seed.config.js` in your project root to customize defaults:
```js
// seed.config.js
module.exports = {
docsPerModel: 25,
includeModels: ["User", "Post"],
dropBeforeSeed: false,
useTransactions: false,
};Library usage
import mongoose from "mongoose";
import { seedDatabase } from "@alieutech/seedsmith";
await mongoose.connect("mongodb://localhost:27017/mydb");
await seedDatabase(mongoose, {
// modelsPath: "./models", // optional: if omitted, uses already-registered models
docsPerModel: 20,
includeModels: ["User", "Post"],
dropBeforeSeed: false,
useTransactions: false,
});
await mongoose.disconnect();Notes
- SeedSmith throws if
NODE_ENVisproduction. - Models must register themselves with Mongoose (e.g.,
mongoose.model('User', userSchema)). - CLI loads
seed.config.jsif present and merges with flags.
Security
- Never hardcode credentials in code or docs. Prefer environment variables (e.g.,
MONGO_URI) or a secrets manager. - Avoid passing credentials directly in shell history. Use
export MONGO_URI=...or a.envfile that is not committed. - Use a least-privilege database user for seeding (only the necessary permissions for inserts/updates).
- If credentials were exposed, rotate them immediately and revoke any leaked tokens.
- Keep seeding to non-production environments; SeedSmith blocks when
NODE_ENV=production.
