Greeting all!
I defined a Mongoose schema as below and registered a model (InventoryItemModel). Is there a way to create a custom constructor function for the schema, so that when I instantiate an object from the model, the function will be called (for example, to load the object with value from database)?
var mongoose = require('mongoose')
, Schema = mongoose.Schema
var InventoryItemSchema = new Schema({
Sku : String
, Quanity : Number
, Description : String
, Carted : []
, CreatedDate : {type : Date, default : Date.now}
, ModifiedDate : {type : Date, default : Date.now}
});
mongoose.model('InventoryItem', InventoryItemSchema);
var item = new InventoryItem();
Can I add some custom constructor function so that the item will be populated from database upon instantiation?