我正在使用MongoDB 4.0。
我的收藏集中的文档可以有一个numbers
字段,该字段包含一个整数数组。通过使用下面的代码,我们可以验证numbers
确实是一个数组,但是可以确保它们是整数吗?
properties: {
numbers: {
bsonType: 'array'
}
}
我看过validation docs和BSON type docs,但其中任何一个都没说什么。一个示例显示了一个用方括号(["double"]
)包围的字段,但是该类型并未描述为数组,因此添加方括号似乎没有效果。
答案 0 :(得分:1)
似乎还有一个属性items
,您可以在其中为数组中的项目定义方案
properties: {
numbers: {
bsonType: 'array'
items: {
bsonType: 'int'
}
}
}
此属性似乎为be from mongo 3.6