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.
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:
+-- joigoose@6.2.0
| +-- @hapi/hoek@8.5.1 deduped
| `-- @hapi/joi@16.1.8 deduped
Install the same version of @hapi/joi, by doing:
npm install @hapi/joi@16.1.8
Unfortunately, until now, the latest version of joigoose is not compatible with @hapi/joi 17.x version.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.