mongodb - 使用具有正确参考文档的 mongo id 数组创建 dto 属性
问题描述
我在 Nestjs 应用程序中有这个创建 DTO
class CurrencyItem {
@IsMongoId()
@Prop({ type: MongooseSchema.Types.ObjectId, ref: Currency.name })
currency_id: string;
}
export class CreateQuotationDto {
@IsNotEmpty()
quote_name: string;
@IsNotEmpty()
@IsMongoId()
@Prop({ type: MongooseSchema.Types.ObjectId, ref: Supplier.name })
supplier: string;
@IsNotEmpty()
@IsMongoId()
@Prop({ type: MongooseSchema.Types.ObjectId, ref: Currency.name })
currency: string;
@IsArray()
@ValidateNested({ each: true })
@Type(() => CurrencyItem)
conversion_currencies: CurrencyItem[];
shipping_company: string;
shipping_rate: number;
custom_charges: number;
@IsNotEmpty()
@Type(() => OtherCharges)
other_charges: OtherCharges[];
@IsNotEmpty()
@Type(() => QuoteItem)
items: QuoteItem[];
date: number;
}
我想做的第一件事是从对象数组中删除 currency_id 并且只想要一个 mongo id 数组,例如:
{
"quote_name": "batch 1",
"supplier": "60a25a84ef72ff68d8e467c6",
"currency": "60a39051ad18d0747e51bfd5",
"conversion_currencies": ["60a25a84ef72ff68d8e467c6", "60a39051ad18d0747e51bfd5"],
"other_charges": "23",
"items": "123"
}
我还想验证我保存的 id 文件是否存在于货币集合中?到目前为止,我能够在对象数组中验证 mongo id
任何帮助也将不胜感激,@Prop
验证在这里不起作用
解决方案
推荐阅读
- reactjs - Next.js组件在 Netlify 上慢,在 Vercel 上快
- flutter - onUserLocationUpdated 没有进入函数
- java - 违反 Java 运行时(Java 运行时环境检测到致命错误)
- gradle - gradle android app build:使用 groovy 内联函数创建动态 archicesBaseName
- vue.js - Nuxt.js - 在页面中添加两个布局
- open-telemetry - 所有功能的 OpenTelemetry Dotnet 跟踪
- sql - PostgreSQL 从另一个表更新一个表数据
- python - 将整数附加到空列表,然后打印这些整数(井字游戏)
- java - 同一个 Java 类中的两个不同的迭代器
- firebase - 使用 firebase 托管时无法加载 mp4 格式的视频