我正在尝试使用 mongo db 实现博客文章存储.
I'm trying to implement blog post storage using mongo db.
我有两个域实体:
博文"和作者"
目前我已将 AuthorId 属性添加到博客文章实体.这是存储对象之间关系的正确方法吗?
Currently I've added AuthorId property to blog post entity. Is that the right approach to store relation between objects?
推荐答案目前我已将 AuthorId 属性添加到博客文章实体.这是存储对象之间关系的正确方法吗?
Currently I've added AuthorId property to blog post entity. Is that the right approach to store relation between objects?
我会说不.您应该"以 非规范化 方式将所需的所有内容存储在博客文档中(例如博客文章、评论、标签等).所以如果你想显示作者的名字,你应该把它添加到博客文档中.这将允许通过单个查询获取整个页面的数据,这有点像面向文档的数据库.
I'd say no. You are "supposed" to store everything you need in a blog document in a denormalized way (e.g. the blog post, the comments, the tags, etc). So if you want to show the Author's name, you should add it to the blog document. This would allow to fetch an entire page's data with a single query, which is kinda the point of a document-oriented database.
更多推荐
对象之间的 Mongo DB 关系
发布评论