@deloittesolutions/joi-mongodb-extensions
v1.0.0
Published
> JOI extension to validate MongoDB types
Downloads
7
Keywords
Readme
joi-mongodb-extensions
JOI extension to validate MongoDB types
Install
Install the profile with npm
:
npm i -S joi @deloittesolutions/joi-mongodb-extensions
Usage
ObjectId
Validate object ids:
const joi = require('joi');
const mongodb = require('@deloittesolutions/joi-mongodb-extensions');
const schema = joi.object().keys({
_id: mongodb.objectId().valid(),
});
const data1 = {_id: '582c2d9b70810501cd336da2'};
const result = joi.validate(data1, schema);
// result.value = {_id: ObjectId('582c2d9b70810501cd336da2')}
const data2 = {_id: new ObjectId('582c2d9b70810501cd336da2')};
const result = joi.validate(data2, schema);
// result.value = {_id: ObjectId('582c2d9b70810501cd336da2')}