mongodb - 是否可以在 mongo db 验证中使用 if then 条件?
问题描述
在 mongo db compass 我想使用验证模式,但我的属性是一个枚举,取决于这个字段,另一个字段可以切换我可以使用 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',
],
};
解决方案
不。
MongoDB文档表明它正在使用草案 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
推荐阅读
- ios - 如何在 Podfile 而不是 podspec 中设置“exclude_files”
- javascript - @firebase/testing - 如何使用 auth.providerId 调用`initializeTestApp`?
- android - android 权限已添加到谷歌商店,但它不在 APK 中
- java - Java 中这种复合赋值的求值顺序是什么?
- r - RStudio - template_dfa 中的错误:尝试运行文档时找不到对象'_htmltools_template_dfa'
- javascript - 在翻译的游戏世界中获取鼠标位置:processing.js
- javascript - 带有动态数据目标的下拉列表中的嵌套可折叠复选框?
- javascript - 在javascript中为sharepoijnt调用函数时出错
- java - 如何在 java 中简化 if-else 语句?
- java - JoinColumn Hibernate / API