0.0.5 • Published 1 year ago
nestjs-module-mongodb v0.0.5
nestjs-module-mongodb
NestJS module for MongoDB
Installation
npm install nestjs-module-mongodb
Usage
// app.module.ts
import { Module } from "@nestjs/common";
import { MongoModule } from "nestjs-module-mongodb";
@Module({
imports: [MongoModule.forRoot("mongodb://localhost:27017/test")],
})
export class AppModule {}
// example.module.ts
import { Module } from "@nestjs/common";
import { MongoModule } from "nestjs-module-mongodb";
@Module({
imports: [MongoModule.registerCollection("example")],
})
export class ExampleModule {}
// example.service.ts
import { Injectable } from "@nestjs/common";
import { InjectCollection } from "nestjs-module-mongodb";
import type { Collection } from "mongodb";
@Injectable()
export class ExampleService {
constructor(
@InjectCollection("example") private readonly collection: Collection
) {}
}