I have a mongoose schema with a boolean field which I want to have a default value of false
. My first guess how to do that was like that:
active: { type: Boolean, default: false }
But for some reason mongoose is always setting the field to true
.
What can I do to change that?
Looks like you are missing something. setting default: false
for that field will auto set it to false.
const mongoose = require('mongoose');
const projectSchema = new mongoose.Schema({
isUsed: {
type: Boolean,
default: false
}
});
mongoose.model('Project', projectSchema, 'project');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With