包含价格详情
在这一步骤中,我们将通过创建一个支持多种定价场景和货币管理的全面定价结构来增强我们的产品模式。
首先,继续在 MongoDB shell 中操作:
mongosh product_catalog
我们将创建一个更详细的定价模型,支持多种定价策略:
db.products.updateOne(
{ name: "Wireless Noise-Canceling Headphones" },
{
$set: {
pricing: {
base: {
amount: 199.99,
currency: "USD"
},
retail: {
amount: 219.99,
currency: "USD"
},
discounts: [
{
type: "SEASONAL",
percentage: 10,
startDate: new Date("2024-01-01"),
endDate: new Date("2024-01-31")
},
{
type: "LOYALTY",
percentage: 5,
conditions: "For members with 1+ year membership"
}
],
taxRates: {
standard: 0.08,
reduced: 0.05
},
priceHistory: [
{
date: new Date("2023-12-01"),
amount: 189.99
},
{
date: new Date("2024-01-01"),
amount: 199.99
}
]
}
}
}
);
让我们创建一个单独的定价集合,以支持更复杂的定价策略:
db.pricing_rules.insertOne({
productId: "TECH-SOUND-NC-001",
dynamicPricing: {
enabled: true,
algorithm: "supply-demand",
minPrice: 150.0,
maxPrice: 250.0
},
bulkPricing: [
{
quantity: { min: 1, max: 10 },
discount: 0
},
{
quantity: { min: 11, max: 50 },
discount: 0.05
},
{
quantity: { min: 51 },
discount: 0.1
}
]
});
验证更新后的产品定价:
db.products.findOne({ name: "Wireless Noise-Canceling Headphones" });