MongoDb:嵌入与引用
我有以下集合:
- 客户包含产品包含项目包含任务和
- 公司包含子公司包含部门包含用户(并且用户包含自定义属性)
最佳实践是什么?如何更有效地使用mongodb?
对我来说,用户和项目会更频繁地更改,应该定义为单独的集合。
你有什么建议?
I have the following collections:
- Client contains Product contains Project contains Task and
- Company contains Subsidiary contains Department contains Users (and user contains custom properties)
What is the best practice? How to use mongodb more efficiently?
As for me, Users and Projects will be changed more often and should be defined as separate collections.
What is your advise?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于你的问题没有统一的答案,因为 MongoDB 允许你同时进行嵌入和引用。
但这里有一些提示:不要使集合膨胀,因为查询下面深处的元素可能很困难,特别是当您要使用列表时。
如果您能够进行原型设计,请尝试首先嵌入集合,然后编写一个单元测试来添加/删除/查询项目和用户。如果这可行,那么就没有必要引用它们。
There is no unified answer for you question, as MongoDB allows you to do both embedding and reference.
But here are some tips: don't bloat a collection, because querying the elements deep below might be hard, especially if you're going to use lists.
If you are able to prototype, try embedding the collections first and then write a unit test which will add/remove/query projects and users. If that would work, then there's no need to reference them.