我正在使用通过JSON模式验证的Mongodb的oneOf验证器。据我所知,MongoDb支持架构验证的草案4,我正在使用的验证规则在this online validator]中显示为有效
{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "additionalProperties": false, "properties": { "foo": {}, "bar": {} }, "oneOf": [ { "type": "object", "properties": { "foo": {} }, "additionalProperties": false }, { "type": "object", "properties": { "bar": {} }, "additionalProperties": false } ] }
我正在传递的输入文件是
或属性bar的对象时,它为什么会失败?{ "bar": {}, }
为什么当我在Mongo中使用相同的架构验证并传入具有属性foo
{
$jsonSchema: {
bsonType: 'object',
additionalProperties: false,
properties: {
foo: {
bsonType: 'string'
},
bar: {
bsonType: 'string'
}
},
oneOf: [
{
bsonType: 'object',
properties: {
foo: {
bsonType: 'string'
}
},
additionalProperties: false
},
{
bsonType: 'object',
properties: {
bar: {
bsonType: 'string'
}
},
additionalProperties: false
}
]
}
}
db.dmt2.insert({"bar": ""})
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 121,
"errmsg" : "Document failed validation"
}
})
我正在使用通过JSON模式验证的Mongodb的oneOf验证器。据我所知,MongoDb支持模式验证的草案4,而我正在使用的验证规则在此在线上显示为有效...
通过指定_ id