Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@synap/nest-mongoose-module

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@synap/nest-mongoose-module

An extension of Nest's MongooseModule with updated mongoose package and ability to add schema hooks with dependency injection.

  • 2.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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 {}

FAQs

Package last updated on 12 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc