对象之间的Mongo DB关系 [英] Mongo DB relations between objects

查看:95
本文介绍了对象之间的Mongo DB关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆