Mondel CLI
The Mondel CLI lets you manage schema synchronization outside app startup.
All commands can run with direct flags or a config file.
Config-First Workflow
bash
npx mondel pull --config ./mondel.config.ts
npx mondel push --config ./mondel.config.tsmondel.config.ts example:
ts
import "dotenv/config";
import type { MondelCliConfig } from "mondel";
export default {
uri: process.env.MONGODB_URI,
pull: {
format: "ts",
outDir: "./src/db/schemas",
perCollectionFiles: true,
},
push: {
schemaFile: "./dist/schemas.js",
schemaExport: "schemas",
applyValidators: true,
dropIndexes: false,
},
} satisfies MondelCliConfig;Config Properties
uri
- MongoDB connection string.
- Database is inferred from this URI.
pull.format
- Output type for pull.
ts: generate Mondel schema file(s).json: generate schema manifest JSON.
pull.outFile
- Output file path for single-file generation.
- Example:
./src/db/schemas.ts.
pull.outDir
- Output directory for folder generation.
- Usually used with
perCollectionFiles: true.
pull.perCollectionFiles
- When
true, generates one*.schema.tsper collection plusindex.ts.
push.schemaFile
- Path to built JS module that exports schemas (default export name:
schemas). - Example:
./dist/schemas.js.
push.manifestFile
- Path to manifest JSON generated by
pull --format json.
push.schemaExport
- Export name in
schemaFileto read schema array from. - Default:
"schemas".
push.applyValidators
- When
true, applies MongoDB validators ($jsonSchema) using schema definitions.
push.dropIndexes
- When
true, removes remote indexes not present in local schema definitions.
push.dryRun
- When
true, only prints actions without applying DB changes.
Install / Run
bash
npx mondel helpCommands
npx mondel pull
Pulls schema metadata from a remote MongoDB database.
Capabilities:
- read collections from a database
- infer fields from sample documents
- read existing indexes
- generate a single TypeScript schema file
- generate one TypeScript file per collection
- export JSON manifest
Examples:
bash
# Single TypeScript file
npx mondel pull --uri mongodb://localhost:27017/app --out ./src/db/schemas.ts
# One file per collection + index.ts
npx mondel pull --uri mongodb://localhost:27017/app --out-dir ./src/db/schemas --per-collection
# JSON manifest
npx mondel pull --uri mongodb://localhost:27017/app --format json --out ./schema-manifest.jsonnpx mondel push
Pushes local schema definitions to MongoDB.
Capabilities:
- create/update indexes from Mondel schema definitions
- optional collection validators (
--apply-validators) - optional index cleanup (
--drop-indexes) - dry run preview (
--dry-run) - source from schema module (
--schema) or JSON manifest (--manifest)
Examples:
bash
# Push from built schema module
npx mondel push --uri mongodb://localhost:27017/app --schema ./dist/schemas.js --apply-validators
# Push from manifest
npx mondel push --uri mongodb://localhost:27017/app --manifest ./schema-manifest.json --drop-indexes
# Dry run
npx mondel push --uri mongodb://localhost:27017/app --schema ./dist/schemas.js --dry-runShared Options
--config <file>: path to config file (.ts,.js,.mjs,.cjs,.json)--uri <mongodb-uri>: MongoDB connection string- Database is implicit in URI. No dedicated
databaseproperty in config.
You can still override config values with CLI flags:
bash
npx mondel pull --config ./mondel.config.ts --out ./tmp/schemas.ts
npx mondel push --config ./mondel.config.ts --dry-runPull Output Modes
- Single file mode: use
--out ./path/to/file.ts - Per-collection mode: use
--out-dir ./path/to/dir --per-collection
Per-collection mode writes:
- one
*.schema.tsfile per collection - one
index.tsexportingschemas - schema variable binds are generated as singular camelCase Example:
users_log->userLog
Push Input Modes
- Module mode:
--schemapoints to a built JS module that exportsschemas - Manifest mode:
--manifestpoints to JSON generated bypull --format json
Notes
syncIndexesoncreateClientis deprecated and kept for backward compatibility.- Recommended flow: run
npx mondel pushin CI/deploy scripts.
