hoangtd97 / hmve Goto Github PK
View Code? Open in Web Editor NEWHandle mongoose validation error
Handle mongoose validation error
hmve is working well when validating unique fields errors for single items being post to the mognodb.
in simple other words:
const { Schema, model } = require('mongoose')
const schema = new Schema({
name: {
type: String,
unique: true
}
})
const Model = model('x', schema)
Model.create( { name: "first" } ) // works!
// ... after some time
Model.create( { name: "first" } ) // hmve detects that this is a duplicate field, good ๐๏ธ, hmve is working
however, if you want to save in a bulk, ie, save multiple documents at the same time, hmve is not going to see that there is duplicate fields:
Model.insertMany( [ { name: "first" }, { name: "first" }, { name: "first" } ] ) // hmve didn't recognize that, and the output on the console of the error is:
// BulkWriteError: E11000 duplicate key error collection
I know that hmve only validates for mongoose validation errors, but this should be also supported, since the developer would probably rely on hmve for this kind of job.
You should add a way to exclude fields from being handled by hmve, after reading the readme.md, you're showing how to execlude error types such as "required, min, max..." but what about excluding some fields from being checked by hmve such as "username" and "email".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.