I have a test schema with mongoose in nodejs like
testschema = mongoose.Schema({
name:{
type:String,
required:true,
unique:true
},
image:{
type:String,
required:true
},
category:{
type:String
},
});
How can i make the category field as optional and make it default to blank if not given by user?
I tried
category:{
type:String,
optional: ''
},
but when printing out the documents saved with the scheme it doesnt even shows the field category.