Registry / database / loopback-mongodb-migrate

loopback-mongodb-migrate

JSON →
library0.3.4jsnpmunverified

A LoopBack 4 component for managing MongoDB schema migrations. Current stable version: 0.3.4 (released Dec 2022). Provides a migration service that allows creating, tracking, and executing migration scripts against MongoDB datasources. Integrates with LoopBack 4's dependency injection system via component registration. Supports CLI-based migration file generation and programmatic migration execution. Differentiates from other LoopBack migration tools by being MongoDB-specific and leveraging the LoopBack 4 component architecture. Ships TypeScript type definitions. Peer dependency on @loopback/core ^4.0.2.

npm install loopback-mongodb-migrate
INSTALL
IMPORT
SIG · LOOPBACK-MONGODB-M
L
loopback-mongodb-migrate
databasejavascriptv0.3.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MongoDBMigrateComponent
import { MongoDBMigrateComponent } from 'loopback-mongodb-migrate'
const { MongoDBMigrateComponent } = require('loopback-mongodb-migrate')
ESM-only package; CommonJS require works via Node interop but ESM is preferred
MongoDBMigrateComponentBindings
import { MongoDBMigrateComponentBindings } from 'loopback-mongodb-migrate'
Provides binding keys for component configuration and services
IMigrationService
import { IMigrationService } from 'loopback-mongodb-migrate'
import { MigrationService } from 'loopback-mongodb-migrate'
Interface is named IMigrationService, not MigrationService
RepositoryModules
import { RepositoryModules } from 'loopback-mongodb-migrate'
Type used in migration script to collect repositories
Application (type)
import { Application } from 'loopback-mongodb-migrate'
import { Application } from '@loopback/core'
loopback-mongodb-migrate re-exports a specific Application type for use in migration scripts

Shows how to register the MongoDBMigrateComponent in a LoopBack 4 app and create a migration script.

// project/src/application.ts import { MongoDBMigrateComponent, MongoDBMigrateComponentBindings } from 'loopback-mongodb-migrate'; export class MyApplication extends BootMixin(ServiceMixin(RepositoryMixin(RestApplication))) { constructor(options: ApplicationConfig = {}) { super(options); this.configure(MongoDBMigrateComponentBindings.COMPONENT).to({ DB_BACKUP_DIR: process.env.DB_BACKUP_DIR ?? '../mongodb-backup', DATASOURCE_URL: process.env.DATASOURCE_URL ?? 'mongodb://localhost:27017/mydb', }); this.component(MongoDBMigrateComponent); } } // project/src/migrate.ts import { IMigrationService, RepositoryModules, MongoDBMigrateComponentBindings, Application, } from 'loopback-mongodb-migrate'; import { MyApplication as App } from './application'; import * as Repositories from './repositories'; export async function migrate(args: string[]) { const app = new App(); await app.boot(); const migrationService = app.getSync<IMigrationService>(MongoDBMigrateComponentBindings.MIGRATION_SERVICE); const repositories: RepositoryModules = await migrationService.getRepositories(app as Application, Repositories); await migrationService.migrate(args, repositories); process.exit(0); } migrate(process.argv).catch(err => { console.error('Cannot migrate database schema', err); process.exit(1); });
Debug
Known issues
breakingRequires Node.js 14+ (engines: 14, 16, 17, 18). Not compatible with Node 12 or 19+.
fix
Upgrade to Node >=14 and <=18, or wait for newer version supporting later Node releases.
affects: <0.4.0
deprecatedThe 'Application' type re-exported from this package may not align with all LoopBack 4 versions; prefer importing directly from '@loopback/core' when using for general purposes.
fix
Use import { Application } from '@loopback/core' instead of from 'loopback-mongodb-migrate' outside the migration script context.
affects: >=0.1.0
gotchaThe component expects both DB_BACKUP_DIR and DATASOURCE_URL to be configured; missing either will cause runtime errors.
fix
Ensure both configuration keys are provided in the configure() call.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'getSync')
Component not registered or application not booted before accessing services.
fix
Ensure this.component(MongoDBMigrateComponent) is called in constructor and app.boot() is awaited before calling app.getSync.
Error: Cannot find module 'loopback-mongodb-migrate'
Package not installed or missing node_modules.
fix
Run 'npm install loopback-mongodb-migrate' in the project root.
Argument of type 'MyApplication' is not assignable to parameter of type 'Application'
Using incompatible Application type imported from '@loopback/core' instead of the re-exported one.
fix
Use import { Application } from 'loopback-mongodb-migrate' in migration script.
Upgrade
Version history
0.3.4latest on npm
Audit
Dependencies
@loopback/corerequiredpeer dependency required for component registration and DI
Agent activity
4 hits · last 30 days
node
4
Resources
loopback-mongodb-migrate — npm install loopback-mongodb-migrate · libregistry