@jchpro/nest-mongoose
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Nest Mongoose

Utilities for Nest.js apps using Mongoose. Includes Migrate CLI for database migrations.

Description

Currently only Migrate CLI is implemented, and in its most basic capability. More stuff probably coming soon.

Installation

npm i @jchpro/nest-mongoose

I'm not a fan of installing too many CLIs globally, so in this document I'll be showing example commands run using npx, assuming that the package is installed locally in your project.

Migrate CLI usage

Setup

npx mongo-migrate setup <applicationProject> <options...> 

This will add mongoMigrate section to the package.json, based on your input options. Please run the command with --help to get more info.

Generate

npx mongo-migrate generate "Some descriptive name of the migration" 

This will generate the migration file in the project (--project option or uses the default one) and regenerate the "collector" file.

Running migrations on app startup

// app.module.ts

// Default name of the "collector" file.
import migrations from './app.migrations';

@Module({
  imports: [
    // Import the Migration module with migrations
    MongoMigrateModule.withMigrations(migrations),
  ]
})
export class AppModule { }
// main.ts

import { Migrator } from '@jchpro/nest-mongoose';

async function bootstrap() {
  // Prepare your app here
  const app = await NestFactory.create(AppModule);
  
  // Run database migrations `up`
  await new Migrator(app).up();
}

Readme

Keywords

Package Sidebar

Install

npm i @jchpro/nest-mongoose

Weekly Downloads

0

Version

0.2.0

License

LGPL-3.0-only

Unpacked Size

71 kB

Total Files

39

Last publish

Collaborators

  • jchpro