This package has been deprecated

Author message:

package renamed to joi-mongodb-oid

joi-mongodb
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

joi-mongodb

Joi custom validator for MongoDB ObjectId.

Install

npm install joi-mongodb

CommonJS 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(),
});

Similar Packages

Package Sidebar

Install

npm i joi-mongodb

Weekly Downloads

1

Version

2.0.1

License

MIT

Unpacked Size

12.8 kB

Total Files

9

Last publish

Collaborators

  • merlin4