I\'m using mongoose schemas for node.js along with express-validator (which has node-validator santiziations and validators).
What\'s a good way to store price for a
Hint: The method described here is basically just another implementation of chovy's answer.
If you have trouble to define getters and setters directly in the schema, you could also use the schema.path() function to make this work:
var ItemSchema = new Schema({
name: String,
price: Number
});
// Getter
ItemSchema.path('price').get(function(num) {
return (num / 100).toFixed(2);
});
// Setter
ItemSchema.path('price').set(function(num) {
return num * 100;
});