Registry /
database / loopback-mongodb-migrate
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);
});
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'getSync')
Component not registered or application not booted before accessing services.
fixEnsure 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.
fixRun '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.
fixUse import { Application } from 'loopback-mongodb-migrate' in migration script. Audit
Dependencies
@loopback/corerequiredpeer dependency required for component registration and DI