Reputation: 308
Quick question, is there a way for a field to have a maximum value in mongodb? For example the field “cards” can only have a maximum value of 100. So if you would increment above it it would return to its maximum value.
Upvotes: 2
Views: 955
Reputation: 74
In mongoose:
const testSchema = new Schema({
name: String,
value: { type: Number, min: 0, max: 100, default: 0 }
});
If value 100 and you want to increment this it return error
Upvotes: 2