在mongo db罗盘上,我想使用一个验证模式,但是我的属性上是一个枚举,根据此字段,可以切换另一个字段,我可以使用JSON模式来做到这一点,但似乎没有为什么在mongoDB指南针上工作?
{
type: 'object',
properties: {
type: {
enum: ['teacher', 'student']
},
firstname: {
type: 'string',
},
lastname: {
type: 'string',
},
login: {
type: 'string',
},
pwd: {
type: 'string'
},
"if": {"properties": {"type": {"const": "student"}}},
"then": {"properties": {classes: {type: "array"}}}
},
required: [
'type',
'firstname',
'lastname',
'login',
'pwd',
],
};
答案 0 :(得分:1)
否。
MongoDB documentation表示它正在使用草案4:
JSON Schema object is formatted according to draft 4 of the JSON Schema standard.
JSON Schema网站说这些条件是草案7中的新条件:
New in draft 7 if, then and else keywords