mongo-sanitize-save
v1.0.1
Published
Sanitize string fields before saving/updating. Regex validation supported.
Downloads
5
Maintainers
Readme
Mongo Sanitize
Sanitizes string fields before saving/updating a document into a mongo collection.
Usage
const mongoose = require("mongoose");
const sanitize = require("mongo-sanitize-save");
let Schema = mongoose.Schema;
let inner_schema = new Schema({
inner_name: {type:String},
inner_title:{type:Number},
date:{type:Date}
});
let outer_schema = new Schema({
title:{type:String},
subtitle:{type:String},
str_array: [{ type: String,required: true}],
details: [inner_schema]
});
sanitize.sanitizeSchema(outer_schema);
sanitize.sanitizeSchema(inner_schema);
exports.default = mongoose.model('my_collection', outer_schema);