Reputation: 370
I am using @hapi/joi
for validation in mongoose schema. I am converting joi object in mongoose schema using joigoose
as follows :
import mongoose from 'mongoose';
import joi from '@hapi/joi';
const joigoose = require('joigoose')(mongoose);
let objectId = mongoose.Schema.Types.ObjectId;
let userInfo = joi.object().keys({
userId: joi.string().required().alphanum().meta({ type: 'objectId' }),
firstName: joi.string().required().min(4).max(20),
lastName: joi.string(),
birthDate: joi.date(),
email: joi.string().email(),
mobile: joi.number().max(10),
isActive: joi.boolean()
})
let userInfoSchema = new mongoose.Schema(joigoose.convert(userInfo));
module.exports = mongoose.model('userInfoModel', userInfoSchema, 'userInfo');
This is throwing error as follows:
I am not able to figure out what is the problem.
Upvotes: 0
Views: 845
Reputation: 26
UPDATE: Joigoose has fixed this error in 7.0.0 version: https://github.com/yoitsro/joigoose/issues/36
Run the command below to list all dependencies of packages in your project's folder
npm list
Find in the tree the joigoose and its dependencies:
+-- [email protected]
| +-- @hapi/[email protected] deduped
| `-- @hapi/[email protected] deduped
Install the same version of @hapi/joi, by doing:
npm install @hapi/[email protected]
Unfortunately, until now, the latest version of joigoose is not compatible with @hapi/joi 17.x version.
Link: https://github.com/yoitsro/joigoose/issues
Upvotes: 1