MongoDB 表方案设计 - 最佳实践。使用主文档(如主表 RDBMS 中)或不使用
背景: 我正在我的项目中对 MongoDB 的使用进行原型设计,其中我使用一些主表来存储定义并在数据表中使用这些键。 我的几个主表是
Class Master_Feed_Provider { int key;
string feed_provider_name
string address }
Class Master_File_Types {int id;
string type }
我的数据表是
Class Data_Feeds {int id,
int file_type_key , int feed_provider_key ,
DateTime time }
**这里我使用 feed_provider_key 来链接 master_feed_provider 的详细信息
所以这里我怀疑 mongoDb 确实支持这种设计,但是我应该采用这种设计还是我应该保留 feed_provider 的完整详细信息和 data_feed 表条目中的 file_types 仅代替键并使用联接获取信息?
在我的数据表中保留完整的详细信息(代替仅 key )将增加数据大小。 保留键并使用联接来链接详细信息将导致额外的数据库操作。 那么这里哪种方式更好呢?
Background :
I am prototyping use of MongoDB in my project where i am using some master tables to store definitions and using these keys in data tables.
my few master tables are
Class Master_Feed_Provider { int key;
string feed_provider_name
string address }
Class Master_File_Types {int id;
string type }
My data table is
Class Data_Feeds {int id,
int file_type_key , int feed_provider_key ,
DateTime time }
**here i use feed_provider_key to link the details from master_feed_provider
So here my doubt is mongoDb does support this kind of design , but should i go for this design or i should just keep full details of feed_provider and file_types in my data_feed table entries in place of only keys and fetch info using joins ?
Keeping full details in my data tables (in place of only key ) will increase the data size.
and Keeping keys and using joins to link details will result in extra db operations.
So which way is better here ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先:与 RDBMS 不同,没有“这是在 mongo 中执行此操作的正确方法”。做出的每一个决定都应该基于常识。这是描述可能的设计决策的链接:链接。正如它所说,有 2 个选项:
主供稿:
1)
2)
First of all: there is no "This is the right way to do it in mongo" unlike in RDBMS. Every decision made should be based in common sense. This is the link describing possible design decisions: link. As it tells there are 2 options:
masterfeeds:
1)
2)
您应该考虑使用
ObjectId
值作为您的键。你的问题有点难以理解,但总的来说,MongoDB 可以支持传统的关系模型,但是因为数据库中没有联接,所以你必须在应用程序中执行它们,这通常意味着对数据库的多个请求。
相反,您通常希望对数据进行某种非规范化,并可能存储所需字段的副本,以便可以在更少的往返次数中满足请求。
请参阅MongoDB:您是否仍应提供链接到其他集合的 ID 或仅包含集合?
You should look into using
ObjectId
values for your keys.Your question is somewhat hard to understand but overall MongoDB can support a traditional relational model BUT because there are no joins in the database you have to do them in your application and that typically means multiple requests to the database.
Instead you typically want to denormalize the data somewhat and perhaps store a copy of the fields that you need so you can satisfy the request in fewer round-trips.
See MongoDB: Should you still provide IDs linking to other collections to or just include collections?
它基本上归结为是否嵌入(子文档)或链接(另一个集合文档)?
看看如何构造多对-猫鼬中有很多关系?了解每种方法的优缺点。
It basically boils down the whether to embed (subdocument) or link(another collection document)?
Have a look at how to structure many-to-many relationships in mongoose? for pros and cons of each approach.