How to version control config stored in MongoDB
If your app reads config from MongoDB (feature flags, prompts, model routing, pricing), people edit those documents live. When something breaks there is no diff, no history and no undo.
This guide adds all three with cfgit, an open-source CLI. The documents stay in MongoDB and your app keeps reading them the same way. It takes about ten minutes. Every output below is from a real run of cfgit 0.6.0.
Install cfgit
cfgit is a Python CLI. It needs Python 3.11 or newer.
pip install 'cfgit[mongo]'Point it at your collection
Create a .cfg.toml next to your app. Name the collection and the field that identifies each document. The connection string comes from an environment variable, never the file.
# .cfg.toml
[project]
name = "control-plane"
[[collection]]
name = "agent_configs"
id_field = "config_id"
[env.dev]
database = "mongo"
uri = "env:DEV_MONGODB_URI"
db = "my-dev-db"export DEV_MONGODB_URI='mongodb://localhost:27017/?replicaSet=rs0'Record what is live today
cfg init creates the history collections next to yours and reports whether your deployment supports atomic writes. cfg doctor checks for secrets and oversized fields. cfg import stores every live document as version 1. Your app keeps reading the same collection.
$ cfg init
$ cfg doctor
$ cfg import --all -m "initial import"
agent_configs:refund_resolution imported
agent_configs:planner imported
$ cfg status
agent_configs:planner clean
agent_configs:refund_resolution cleanPreview a change, then make it
cfg set edits fields in place. --dry-run shows the exact field-level change and writes nothing.
$ cfg set agent_configs:planner provider.model=gemini-2.5-pro --dry-run
agent_configs:planner: would commit (dry run)
change provider.model
before: "gpt-4.1"
after: "gemini-2.5-pro"
$ cfg set agent_configs:planner provider.model=gemini-2.5-pro -m "planner on gemini"
agent_configs:planner: committed @2 443009510d81Read the history
Every version keeps the full document, a content hash, the author and the message. cfg log shows what changed in each one.
$ cfg log agent_configs:planner
agent_configs:planner @2 443009510d81
change provider.model
before: "gpt-4.1"
after: "gemini-2.5-pro"
agent_configs:planner @1 dc981436ca70
...Roll back
cfg restore puts a document back to any earlier version. The rollback is itself a new version, so nothing in the history is lost.
$ cfg restore agent_configs:planner @1 -m "roll back planner"
agent_configs:planner: restored @3 dc981436ca70Catch edits made straight in the database
People and scripts will still edit documents directly. cfgit does not block that, it notices it. cfg status flags the document, cfg diff shows the change, and cfg adopt keeps it as a new version. Until then, cfgit refuses to write over it.
$ cfg status
agent_configs:planner changed_outside_cfgit
agent_configs:refund_resolution clean
$ cfg diff agent_configs:planner =HEAD =live
change temperature
before: 0.2
after: 0.7
$ cfg adopt agent_configs:planner -m "keep the temperature change"
agent_configs:planner: adopted @4 4509193032efLet your coding agent do it
cfgit ships an MCP server, so Claude Code, Codex or Cursor can run the same steps through the same checks. In Claude Code:
/plugin install cfgit --marketplace AusafMo/cfgitOther agents are in the setup menu on the cfgit page.
Next
The cfgit guide covers branches and pull requests for config, promotion from dev to prod, impact analysis and the safety model. Postgres works the same way; see the Postgres guide. For finding hand edits across collections, see detecting config drift, and for agents, safe database writes for coding agents. Weighing other options? See how cfgit compares with audit logs, Dolt, migrations and flag services.