我使用 Nestjs 和 Mongoose 作為 orm。我有一個名為 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 資料庫中,我們創建了一個 ProductPrice 表,其中包含(productId、price、date)。但是由于 mongodb 的最大檔案大小為 16MB 并且我擁有數千種產品&Mongodb 中的最佳解決方案是什么?
uj5u.com熱心網友回復:
這對MongoDB隨意來說并不具有挑戰性,只需ProductHistory為此創建一個集合:
{
id: ObjectId,
product_id: ObjectId,
created_at: Date,
price: 99,
currency: "$",
expiration: 4,
expired: false
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/385499.html
上一篇:對陣列欄位的int值求和
