vik*_*kin 3 validation jsonschema mongodb
我正在使用 $jsonSchema 检查 mongo 层上的 json 模式验证。我需要定义一个多语言对象。我使用$ref。但我收到错误 - $jsonSchema 关键字“定义”当前不受支持根据文档,它必须具有常见的 json 模式行为。
async install(): Promise<void> {
let db = await this.dbContainer.getDb();
let properties = _.fromPairs(this.config.languages.map((language) => {
return [language, {$ref: '#/definitions/post'}]
}));
await db.createCollection(
this.collectionName,
{
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['title', 'summary', 'link'],
definitions: {
post: {
title: {
bsonType: 'string',
description: 'Title is required'
},
summary: {
bsonType: 'string',
description: 'Summary is required'
},
href: {
bsonType: 'string',
description: 'Summary is required'
},
},
},
properties,
}
}
}
);
Run Code Online (Sandbox Code Playgroud)
有人有什么建议吗?我应该使用 json-schema 作为单独的库吗?
| 归档时间: |
|
| 查看次数: |
1433 次 |
| 最近记录: |