【发布时间】:2021-09-30 18:52:59
【问题描述】:
我无法决定我应该对我的 mongodb 数据使用什么数据模型结构。我读过有人说一个大集合是最好的选择,也有人说多个小集合是最好的选择。
我有“用户”,它们将存储在一个集合中。
我看过的选项是:
1.
Users (the collection):
_id (what the documents include)
name
...
Posts:
_id
user_id
title
body
要查找用户的所有帖子,我将查询 .collection("Posts").find({user_id: "123test"})
2.
Users:
_id
name
...
(user1)Posts:
_id
title
body
(user2)Posts:
_id
title
body
(user3)Posts:
_id
title
body
...
要查找用户的所有帖子,我将查询 .collection(user + "Posts").find({})
用户和帖子将不断增长,我想要对大量数据有好处的东西。例如,一个用户可能有 1000-10000 个帖子。 最后可能会有大约 100 个用户。 这将等于 10 000 000 个帖子。 我还将在 Posts 集合上使用具有多个索引的多个过滤器。
我正在使用 Mongodb atlas serverless,那么什么选项是性能最高和最便宜的?
感谢您的宝贵时间:)
【问题讨论】:
标签: database mongodb data-structures data-modeling mongodb-atlas