Custom Joi validator for MongoDB ObjectId.
npm install joi-mongodb-oid
In your application's entry point (index.js/server.js/app.js):
const Joi = require('joi-mongodb-oid')();
Then the objectId()
validator can be used just like any other Joi validator:
const schema = Joi.object({
_id: Joi.objectId(),
name: Joi.string(),
date: Joi.date(),
});
In your application's entry point (index.js/server.js/app.js):
import JoiMongoDB from 'joi-mongodb-oid';
const Joi = JoiMongoDB();
Then the objectId()
validator can be used just like any other Joi validator:
const schema = Joi.object({
_id: Joi.objectId(),
name: Joi.string(),
date: Joi.date(),
});
Inject the objectId validator:
import JoiMongoDB from 'joi-mongodb-oid';
const Joi = JoiMongoDB();
Then the objectId()
validator can be used just like any other Joi validator:
const schema = Joi.object({
_id: Joi.objectId(),
name: Joi.string(),
date: Joi.date(),
});