我已经停止了架构:
var CountrySchema = new mongoose.Schema({
name: String,
relations : { type: Number, default: 0, min : 0, max : 1},
});
var DiplomacySchema = new mongoose.Schema({
year: { type: Number, default: 1900, min : 1900, max: 2020 },
countries: [CountrySchema]
});
使用数据库中的相应文档
{
year: 1950,
countries: [
{
name: "UK",
relations: 0.5
},
{
name: "Germany",
relations: 0.25
}
]
}
我需要在更新值保持在范围边界的约束下,以某个数字更新英国当前的关系。例如,考虑到当前的英国关系为0.5,+ 0.25的更新应该导致0.75,-0.3的更新应该导致0.2,但+0.75的更新应该是1.