2.0.1 • Published 3 years ago
joi-mongodb v2.0.1
joi-mongodb
Joi custom validator for MongoDB ObjectId.
Install
npm install joi-mongodbCommonJS Usage
In your application's entry point (index.js/server.js/app.js):
const Joi = require('joi-mongodb')();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(),
});ESM Usage
In your application's entry point (index.js/server.js/app.js):
import JoiMongoDB from 'joi-mongodb';
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(),
});TS Usage
Inject the objectId validator:
import JoiMongoDB from 'joi-mongodb';
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(),
});