This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 15k traffic Daily!!!

How to set mongoose schema field from list of strings (enum)


Within the following instance we outline template attribute to be of sort String with values outlined within the enum array:

const noteSchema = new Schema({
    title: {sort:String, required: true},
    sort: {sort:String, required: true, default: 'be aware'},
    content material: String,
    reference: String,
    tags: [String],
    template: {sort:String, enum: ['note', 'checklist']},
    userId: {sort: String, ref:'Person'},
    __v: { sort: Quantity, choose: false}
},
{
  timestamps: true
});
Enter fullscreen mode

Exit fullscreen mode


Shared with ā¤ļø from Codever. Use šŸ‘‰ copy to mine performance so as to add it to your private snippets assortment.

Codever is open supply on Githubā­šŸ™

The Article was Inspired from tech community site.
Contact us if this is inspired from your article and we will give you credit for it for serving the community.

This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 10k Tech related traffic daily !!!

Leave a Reply

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

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?