Skip to content

Recipes

Step-by-step guides for real situations: the commands to run, what you'll see, and what to watch out for.

Every command output on these pages is real: it was produced by running MongoMig 0.4.2 against MongoDB, not written by hand. The FastAPI and testing recipes come from a real project, examples/fastapi_store, whose tests run in MongoMig's CI.

Everyday changes

I want to... Recipe
add a field (and fill it in old documents) Add a field with a default
rename a field Rename a field
change a field's type (e.g. string → int) Change a field's type
remove a field, and maybe delete its data Remove a field
add a unique index Add a unique index when duplicates exist
run custom logic over many documents A long custom data migration

Teams and history

I want to... Recipe
start using MongoMig on a database that already exists Adopt an existing database
fix two branches that both changed models Two developers changed models
clean up a long migration history Squash old history

Production

I want to... Recipe
run migrations in CI/CD, Docker, Kubernetes Deploy
use MongoMig in a FastAPI app FastAPI
test my migrations Test your migrations
recover from a migration that failed halfway A migration failed halfway
undo a bad release Roll back a bad release
know when data stops matching my models Monitor drift nightly