Docs/Engines/MongoDB

MongoDB

MongoDB is a document store. There is no SQL DDL: migrations are Python scripts that drive pymongo. A .sql file fails with DBLIFT-NOSQL-001 before anything executes.

Breaking
Host-form auth uses the configured database as authSource

The assembled URI is mongodb://user:pass@host:port/<database>. The driver reads that path as the default authSource, so credentials are checked against that database. Users defined in the database being migrated work; users defined in admin (a root user created in admin, many Atlas setups) are refused. If your user lives in admin, use the url form and name the auth source. Neither shape is affected when authentication is disabled, which is why this is invisible in a default local container.

database:
  type: "mongodb"
  url: "mongodb://user:pass@localhost:27017/?authSource=admin"
  database: "myapp"
type
mongodb
Driver
pymongo
DDL
No transactions
Migrations
Python only

Install

pip install "dblift[cli,mongodb]"

Connection URL

mongodb://user:password@localhost:27017/app

A mongodb:// or mongodb+srv:// URL is accepted as-is. Without a URL, DBLift builds one from host, port, username and password, including /<database> on the path. That path is the driver's default authSource — see the note above. The alias mongo also selects this engine. database is required.

dblift.yaml

database:
  type: mongodb
  url: "mongodb://db.internal:27017/app"
  database: "app"

Engine settings

KeyDefaultEffect
url—A mongodb:// or mongodb+srv:// URI. Atlas TLS, replica-set and auth-source options live here.
host / port27017Used when url is omitted. Port defaults to 27017. With username and password, DBLift authenticates against the configured database, not admin.
database—Required. The MongoDB database name. In the host form this is also the default authSource.

Behaviour notes

SQL migrations are not supported.

Write Python migrations. A .sql file fails with DBLIFT-NOSQL-001. context.execute() of a string raises DBLIFT-NOSQL-002 — MongoDB has no query language for writes.

No transactions, and no transactional DDL.

A migration that fails half-way leaves completed operations in place. Rehearse, and keep each migration small.

schema is not required.

Collections are schemaless. database names the MongoDB database.