我使用Nestjs
和Mongoose
作为ODM。我有一个名为"产品"的模型,它具有以下属性:
产品型号
@Schema({ timestamps: true, id:true, toJSON:{virtuals:true} })
export class Product {
@Prop({ required: true, type: String })
title: string
@Prop({ type: String })
brand: string
@Prop({ type: String })
description: string
@Prop({ type: Number})
currentPrice: number
}
每4小时产品价格将更新一次。我想知道在MongoDB
中存储产品价格历史记录的最佳方式是什么。在像PostgreSQL
这样的SQL数据库中,我们使用(productId,price,date(创建一个ProductPrice表。但由于CCD_ 5的最大文档大小是16MB;MongoDB
的最佳解决方案是什么??
这对MongoDB
来说并不具有挑战性,只需为其创建一个ProductHistory
集合即可:
{
id: ObjectId,
product_id: ObjectId,
created_at: Date,
price: 99,
currency: "$",
expiration: 4,
expired: false
}