mongodb - 验证参考字段是否为空不在月光中工作
问题描述
我的问题是 SchemaA 中的选项字段没有验证它是否为空,即使放置了所需的属性。
这是我的模型的一个例子
const schemaA = new Schema({
title:{
type: String,
required: [true,'this field is required']
},
options: [{
type: Schema.Types.ObjectId,
ref: 'SchemaB',
default: undefined,
required: [true, "cant be empty"]
}]
})
const schemaB = new Schema({
title:{
type: String,
required: [true,'this field is required']
}
})
解决方案
我将 schemaA 选项字段更改为此。
const schemaA = new Schema({
title:{
type: String,
required: [true,'this field is required']
},
options: {
type: [Schema.Types.ObjectId],
ref: 'SchemaB',
default: undefined,
required: [true, "cant be empty"]
}
})
推荐阅读
- indexing - 在 Excel 中查找满足多个条件的匹配项
- php - php 从数组到日期累计添加数字
- sql-server - 针对同一个表结果的外部应用(和交叉应用)
- excel - 如何使用 VBA 将 Google 表格中的数据导入 Excel
- sql - 未对 WHERE 子句中的值进行硬编码时,查看过去 5 天未返回的数据
- vb.net - 如何将数据从浏览器复制到 excel vb.net
- python - 得到第n个素数
- python - 基于日期提取子帧时的问题
- amazon-web-services - AWS CLI 不适用于 VPN 隧道选项
- azure-data-factory - 在 Azure 数据工厂中映射自定义变量