[英]MongoDB best schema design for efficiency
所以我是 mongoDB 的新手,但已经使用了 sql。 我希望这是一个相当简单的问题,所以我会陷入困境。
在以下两种模式设计中,哪一种最有效/最容易查询? 我会做相当简单的查询(我希望如此)。 “销售”对象将比我在下面概述的要复杂得多。 数据库中将有大约 30 家商店,预计在几年内增加到 60 家。
{
name: "shop1",
sales:
[
{
weekEnding: "5/1/2020",
sales: 156.50,
customers: 5
},
{
weekEnding: "12/1/2020",
sales: 256.50,
customers: 12
},
]
},
{
name: "shop2",
sales:
[
{
weekEnding: "5/1/2020",
sales: 456.50,
customers: 9
},
{
weekEnding: "12/1/2020",
sales: 446.50,
customers: 19
},
]
},
{
name: "shop1",
weekEnding: "5/1/2020",
sales: 156.50,
customers: 5
},
{
name: "shop1",
weekEnding: "12/1/2020",
sales: 256.50,
customers: 12
},
{
name: "shop2",
weekEnding: "5/1/2020",
sales: 456.50,
customers: 9
},
{
name: "shop2",
weekEnding: "12/1/2020",
sales: 446.50,
customers: 19
},
我不是 MongoDB 专家,但我认为您选择选项 2 会更好。使用选项 1,您的数据库中只有大约 30 个文档,而且所有文档都可能变得非常大,我认为 MongoDB 将不得不在磁盘上重新排列它们当它们改变大小时,因为对象应该保持在一个连贯的 memory 空间中。
我认为选项 2 完全没有问题。它可以很好地按商店索引销售,并且不会导致任何性能问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.