Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Spark
  3. Question
Spark

How to Create and Use Enum in Mongoose

Asked by Amit Sinha May 12, 2021 1.9K views 1 answer
Share

About this question

I am trying to create and use an enum type in Mongoose. I checked it out, but I'm not getting the proper result. I'm using enum in my mongoose schema as follows:

var RequirementSchema = new mongoose.Schema({ 
status: { 
type: String, 
enum : ['NEW', 'STATUS'], 
default: 'NEW' 
}, 
})

But I am a little bit confused here, how can I put the value of an enum like in Java NEW("new"). How can I save an enum into the database according to its enumerable values? I am using it in express node.js.

Your answer

1 Answer

More Spark discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Spark Blogs

Guides, tips and career advice on Spark from JanBask experts.