MongoDB 模式中基于对等的验证
Peer Based Validation in MongoDB Schema
我正在使用 MongoDB 架构来验证插入数据库的数据。我希望有类似于 Joi 中的 Joi.when()
的基于对等的验证。
数据如下所示:
first:"Teddy",
last:"Bear"
只有当 first 不为空时,我如何使 last required
和 maxLength:10
?我需要在 MongoDB jsonSchema:
中与此等效的内容
last: Joi.string().when('first', { is: null, then: Joi.required().max(10), otherwise:Joi.forbidden() }),
我正在使用 MongoDB 架构来验证插入数据库的数据。我希望有类似于 Joi 中的 Joi.when()
的基于对等的验证。
数据如下所示:
first:"Teddy",
last:"Bear"
只有当 first 不为空时,我如何使 last required
和 maxLength:10
?我需要在 MongoDB jsonSchema:
last: Joi.string().when('first', { is: null, then: Joi.required().max(10), otherwise:Joi.forbidden() }),