0.2.0 • Published 3 years ago

@mongoly/nestjs v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@mongoly/nestjs

The official nest module for mongoly

This package is under heavy development and will continously receive breaking changes, use at your own risk!

Installation

npm install mongodb @mongoly/core @mongoly/nestjs

Usage

// app.module.ts
import { Module } from "@nestjs/common";
import { ensureJSONSchema, ensureIndexes } from "@mongoly/nestjs";

@Module({
  imports: [
    MongolyModule.forRoot({
      url: "mongodb://localhost:27017/dev_mongoly_nestjs",
    }),
    CatsModule,
  ],
})
export class AppModule {}
// cats.module.ts
import { Module } from "@nestjs/common";
import { MongolyModule } from "@mongoly/nestjs";
import { Cat, CatIndexes, CatSchema } from "./cats.entity";
import { CatsService } from "./cats.service";

@Module({
  imports: [
    MongolyModule.forFeature([
      {
        name: Cat.name,
        schema: CatSchema,
        indexes: CatIndexes,
        dropOldIndexes: true,
      },
    ]),
  ],
  providers: [CatsService],
  exports: [CatsService],
})
export class CatsModule {}
// cats.entity.ts
import {
  Schema,
  Prop,
  createJSONSchemaForClass,
  createIndexesForClass,
} from "@mongoly/nestjs";

@Schema()
export class Cat {
  @Prop({ isRequired: true, isIndexed: true })
  name: string;

  @Prop({ isRequired: true, isIndexed: true })
  age: number;

  @Prop({ isRequired: true, isIndexed: true })
  breed: string;
}

export const CatSchema = createJSONSchemaForClass(Cat);
export const CatIndexes = createIndexesForClass(Cat);
// cats.service.ts
import { Injectable } from "@nestjs/common";
import { InjectCollection } from "@mongoly/nestjs";
import type { Collection } from "mongodb";
import { Cat } from "./cats.entity";

@Injectable()
export class CatsService {
  constructor(
    @InjectCollection(Cat.name)
    private readonly catsCollection: Collection<Cat>,
  ) {}
}
0.2.0

3 years ago

0.1.15

4 years ago

0.1.16

3 years ago

0.1.17

3 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago