Skip to content
This repository has been archived by the owner on Sep 26, 2020. It is now read-only.
/ mongoose-construct Public archive

Adds a 'construct' hook to mongoose models. Similiar to the init hook but called even for new objects, not just objects returned by the database

Notifications You must be signed in to change notification settings

tarqd/mongoose-construct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Mongoose Constructor Hook

mongoose-construct adds a hook similiar to the init hook, except it's called everytime a model instance is created, whether it's brand new or loaded from the database (whereas the init hook only gets called when you load the object from the database via find query)

Installation

npm install --save mongoose-construct

Usage

var mongoose = require('mongoose')
  , Schema = mongoose.Schema
  , construct = require('mongoose-construct')

var user = new Schema({})
user.plugin(construct)

user.pre('construct', function(next){
	console.log('Constructor called...')
	next()
})

var User = mongoose.model('User', user)
var myUser = new User(); // construct hook will be called
````

About

Adds a 'construct' hook to mongoose models. Similiar to the init hook but called even for new objects, not just objects returned by the database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published