Closed bradkyle closed 4 years ago
Hey @bradkyle. Please can you try upgrading joi to at least v16: https://www.npmjs.com/package/@hapi/joi then trying again?
@bradkyle Any news on this?
joigoose^6.2.0 is not working with @hapi/joi^17.1.0
Error: Cannot mix different versions of joi schemas
at Object.
Source:
const Mongoose = require("mongoose")
const Schema = Mongoose.Schema
const Joigoose = require("joigoose")(Mongoose)
const Joi = require("@hapi/joi")
const joiProductSchema = Joi.object({
model: Joi.string().alphanum().min(2).max(255).trim().required(),
brand: Joi.string().alphanum().min(2).max(255).trim().required(),
price: Joi.number().positive(),
photo: Joi.string().max(255).trim()
})
const ProductSchema = new Schema(Joigoose.convert(joiProductSchema))
:tada: This issue has been resolved in version 7.0.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
var joiSchema= Joi.object({ username: Joi.string().email({ minDomainSegments: 2, tlds: { allow: ['com', 'net'] } }), email: Joi.string().email({ minDomainSegments: 2, tlds: { allow: ['com', 'net'] } }), password: Joi.string().required(), verifyPassword: Joi.string().required(), firstName: Joi.string().required(), lastName: Joi.string().required(),
})
var userSchema = new mongoose.Schema(
Joigoose.convert(joiSchema)
);
console.log(userSchema)
userSchema.pre('save', function (next) {
var user = this
if (this.isModified('password') || this.isNew) {
bcrypt.genSalt(saltValue, function (err, salt) {
if (err) {
return next(err)
}
bcrypt.hash(user.password, salt, function (err, hash) {
if (err) {
return next(err)
}
user.password = hash
next()
})
})
} else {
return next()
//logger.error('error', User Model - Returning User
)
}
})
module.exports = mongoose.model('User', userSchema)
error : Error: Schema can only contain plain objects
Hi @xark-10. Thanks for reporting this. Please can you open new issue for this as this issue is quite old now.
throws:
OS: Arch Linux npm show joigoose:
npm show mongoose:
npm show joi