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

查看:13
本文介绍了对象之间的 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天全站免登陆