2.0.3 • Published 6 years ago

@synap/nest-mongoose-module v2.0.3

Weekly downloads
1
License
ISC
Repository
bitbucket
Last release
6 years ago

MongooseModule

This is an extension of Nest's MongooseModule. The only differences are 1) The mongoose package is 5.3.1 as opposed to 5.0.1 which is the version included in @nestjs/mongoose 2) The createMongooseProviders method has been updated to allow schema hooks and dependency injection

Usage

import { Module } from '@nestjs/common';
import { MongooseModule, InjectModel } from './';
import { Schema, Model, Document } from 'mongoose';

// CoreModule
@Module({
	imports: [
		MongooseModule.forRoot('mongodb://localhost:27017/my-db', { useNewUrlParser: true }),
		MyModule
	]
})
export class CoreModule {}

// Document Interface
export interface MyDocument extends Document
{
	someProp:string;
}

// MyService
export class MyService 
{
	constructor(@InjectModel('MyModel') private readonly myModel:Model<MyDocument>)
	{
	}
}

// MyModule
@Module({
	imports: [
		MongooseModule.forFeature([{
			name: 'MyModel',
			schema: new Schema({ someProp: { type: String } }),
			hooks: [
				{
					type: 'post',
					method: 'remove',
					fn: async (doc:MyDocument, svc:MyService) => console.log('MyModel.postRemove'),
					inject: ['MyService']
				}
			]
		}])
	]
})
export class MyModule {}
2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago