key «String» options «Object» Buffer SchemaType constructor
fn «Function» Override the function the required validator uses to check whether a string passes the required check.
// Allow empty strings to pass `required` check
mongoose.Schema.Types.String.checkRequired(v => v != null);
const M = mongoose.model({ buf: { type: Buffer, required: true } });
new M({ buf: Buffer.from('') }).validateSync(); // validation passes!
getter «Function» Attaches a getter for all Buffer instances
// Always convert to string when getting an ObjectId
mongoose.Schema.Types.Buffer.get(v => v.toString('hex'));
const Model = mongoose.model('Test', new Schema({ buf: Buffer } }));
typeof (new Model({ buf: Buffer.fromString('hello') }).buf); // 'string'
value «Any» doc «Document» Check if the given value satisfies a required validator. To satisfy a required validator, a buffer must not be null or undefined and have non-zero length.
subtype «Number» the default subtype Sets the default subtype for this buffer. You can find a list of allowed subtypes here.
const s = new Schema({ uuid: { type: Buffer, subtype: 4 });
const M = db.model('M', s);
const m = new M({ uuid: 'test string' });
m.uuid._subtype; // 4
This schema type's name, to defend against minifiers that mangle function names.
option «String» The option you'd like to set the value for value «Any» value for option Sets a default option for all Buffer instances.
// Make all buffers have `required` of true by default.
mongoose.Schema.Buffer.set('required', true);
const User = mongoose.model('User', new Schema({ test: Buffer }));
new User({ }).validateSync().errors.test.message; // Path `test` is required.
© 2010 LearnBoost
Licensed under the MIT License.
https://mongoosejs.com/docs/api/schemabuffer.html