Data Validation using Mongoose in Node JS – MongoDB App

Data validation in MongoDB App can be easily done using the mongoose. Here is some sample validation examples:

Marking Required field in MongoDB using Mongoose

const personSchema = new mongoose.Schema ({
    name: {
        type: String,
        required: true      // marking field as required
    },
    age: {
        type: Number,
        min:18               //setting minimum age validation
});

Mongoose Validation References

About the Author: smartcoder

You might like

Leave a Reply

Your email address will not be published. Required fields are marked *