对象之间的 Mongo DB 关系

编程入门 行业动态 更新时间:2024-10-26 22:21:55
本文介绍了对象之间的 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 关系

本文发布于:2023-11-22 21:06:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619021.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   关系   Mongo   DB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!