【发布时间】:2022-01-21 00:29:11
【问题描述】:
我使用Nestjs 和Mongoose 作为ODM。我有一个名为 Product 的模型,它具有以下属性:
产品型号
@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 表。但是MongoDB 的最大文档大小是 16MB,并且我拥有数千种产品&MongoDB 中的最佳解决方案是什么??
【问题讨论】:
-
您是否尝试过您的 ProductPrice 架构?我没有预见到任何具体的困难。 16 MB 文档大小限制适用于单个文档(或相当于 RDBMS 中的一行),所以我猜您不太可能达到您提到的 3 字段模式的限制。