{"id":42593,"library":"db-migrate-mongodb","title":"db-migrate-mongodb","description":"MongoDB driver plugin for db-migrate, enabling database migrations for MongoDB databases. Current stable version 1.5.0, maintained as part of the db-migrate ecosystem. Provides seamless integration with db-migrate's migration framework, supporting up/down migrations, seed data, and configuration via database.json. Automatically uses the mongodb native driver version 3.x (ships its own dependency). Compared to manual migration scripts, it offers a structured, version-controlled approach with rollback support.","status":"active","version":"1.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/db-migrate/mongodb","tags":["javascript","db-migrate","db","database","migrate","migration","driver"],"install":[{"cmd":"npm install db-migrate-mongodb","lang":"bash","label":"npm"},{"cmd":"yarn add db-migrate-mongodb","lang":"bash","label":"yarn"},{"cmd":"pnpm add db-migrate-mongodb","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Plugin interface and base migration functionality required by all db-migrate drivers","package":"db-migrate-base","optional":false},{"reason":"Native MongoDB driver for database connections and operations","package":"mongodb","optional":false}],"imports":[{"note":"The package is a plugin for db-migrate. It is automatically loaded when configured in database.json. Do not import or require it directly in migration files.","wrong":"import MongoDBDriver from 'db-migrate-mongodb'","symbol":"default (plugin registration)","correct":"No direct import needed; db-migrate auto-discovers driver"},{"note":"Programmatic usage requires passing the driver to db-migrate. The driver module itself does not export a connect function.","wrong":"import { connect } from 'db-migrate-mongodb'","symbol":"connect (if using programmatic API)","correct":"const DBMigrate = require('db-migrate');\nconst mongodb = require('db-migrate-mongodb');\nconst instance = DBMigrate.getInstance(true, { driver: mongodb });"}],"quickstart":{"code":"// database.json\n{\n  \"dev\": {\n    \"driver\": \"mongodb\",\n    \"url\": \"mongodb://localhost:27017/mydb\"\n  }\n}\n\n// migrations/20220101000000-create-users.js\n'use strict';\n\nvar dbm;\nvar type;\nvar seed;\n\nexports.setup = function(options, seedLink) {\n  dbm = options.dbmigrate;\n  type = dbm.dataType;\n  seed = seedLink;\n};\n\nexports.up = function(db, callback) {\n  db.createCollection('users', callback);\n};\n\nexports.down = function(db, callback) {\n  db.dropCollection('users', callback);\n};\n\nexports._meta = {\n  \"version\": 1\n};\n\n// Run: db-migrate up","lang":"javascript","description":"Shows configuration and a sample migration creating and dropping a users collection."},"warnings":[{"fix":"Ensure db-migrate and db-migrate-base are installed alongside this package.","message":"The driver requires both db-migrate and db-migrate-base as peer dependencies; missing them causes cryptic errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Remove any explicit require/import of this package from migration scripts.","message":"do not use require('db-migrate-mongodb') in migration files. It is auto-loaded.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use callback-based API in migration up/down functions; avoid returning promises.","message":"The driver uses mongodb driver v3.x (Callback-based) internally; async/await usage in migrations may lead to timing issues.","severity":"deprecated","affected_versions":"1.x"}],"env_vars":null,"search_vec":"'1.5.0':21 '3':57 'approach':75 'automat':50 'compar':63 'configur':47 'control':74 'current':18 'data':45 'databas':13,17,84 'database.json':49 'db':2,10,28,36,81,83 'db-migrat':9,27,35,80 'db-migrate-mongodb':1 'depend':62 'driver':6,55,87 'ecosystem':30 'enabl':12 'framework':40 'integr':33 'javascript':79 'maintain':22 'manual':65 'migrat':3,11,14,29,37,39,43,66,82,85,86 'mongodb':4,5,16,53 'nativ':54 'offer':69 'part':24 'plugin':7 'provid':31 'rollback':77 'script':67 'seamless':32 'seed':44 'ship':59 'stabl':19 'structur':71 'support':41,78 'up/down':42 'use':51 'version':20,56,73 'version-control':72 'via':48 'x':58","created_at":"2026-06-05T16:55:44.323522+00:00","updated_at":"2026-06-05T16:55:44.323522+00:00","problems":[{"fix":"npm install db-migrate db-migrate-base","cause":"Missing peer dependency db-migrate-base","error":"Error: Cannot find module 'db-migrate-base'"},{"fix":"Make sure exports.setup is called correctly; use the `db` parameter provided in up/down functions.","cause":"Using driver without proper setup or calling db functions before setup","error":"TypeError: db.createCollection is not a function"},{"fix":"Check MongoDB driver documentation for the correct method signature, especially for insert/update operations.","cause":"Passing wrong arguments to MongoDB driver methods","error":"MongoError: first arg must be an object or array"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/db-migrate/mongodb","github":"https://github.com/db-migrate/mongodb","docs":null,"changelog":null,"pypi":null,"npm":"db-migrate-mongodb","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}