简体   繁体   English

Mongodb 为字段设置最大值?

[英]Mongodb set a maximum value for a field?

Quick question, is there a way for a field to have a maximum value in mongodb?快速提问,有没有办法让一个字段在 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.例如,“卡片”字段的最大值只能为 100。因此,如果您将其递增到它之上,它将返回其最大值。

In mongoose:在 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如果值为 100 并且你想增加它,它会返回错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM