A good way to re-use common configurations for schema paths is to set them using a variable.
Like this:
var trimmedString = { type: String, trim: true };
var schema = new Schema({
p1: trimmedString,
p2: trimmedString,
p3: trimmedString,
p4: trimmedString
});
You could also return the definition from a function that sets defaults for you, but allows you two override things (or add other settings, like an index or default).
Like this:
(using the underscore library's defaults method)
var _ = require('underscore');
var stringType = function(ops) {
return _.defaults(ops || {}, {
type: String,
trim: true
});
}
var schema = new Schema({
p1: stringType(),
p2: stringType({ index: true }),
p3: stringType({ default: "something" }),
p4: stringType({ trim: false })
});