0.2.0 • Published 2 years ago

@mongoly/nestjs v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 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

2 years ago

0.1.15

3 years ago

0.1.16

3 years ago

0.1.17

3 years ago

0.1.14

3 years ago

0.1.13

3 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago