How do I set default value of an integer in mongodb?
As you're using Mongoose, you can set the default as part of the Schema
definition:
var userSchema = new Schema({ win: { type: Number, default: 0 }});
The options are documented here. It's also cool that if you set the default to a function, it will execute when the Model is instantiated. For example, if it were: default: Date.now
, it will call the Date.now()
function when a model is created.