我正在接近 noSQL 世界。 我在网络上学习了一些(不是最好的学习方式!)并且阅读了 Mongodb 文档。 在网络上,我找不到真实的案例(只有大型架构上的奇特飞行,没有得到很好的解释,或者太基础而无法成为现实世界的例子)。
所以我对 noSQL 和 Mongodb 的理解仍然存在一些巨大的漏洞。
我尝试总结其中一个,实际上是最糟糕的一个,如下:
让我们想象一下一个简单博客结构的帖子的数据结构:
{
"_id": ObjectId(),
"title": "Title here",
"body": "text of the post here",
"date": ISODate("2010-09-24"),
"author": "author_of_the_post_name",
"comments": [
{
"author": "comment_author_name",
"text": "comment text",
"date": ISODate("date")
},
{
"author": "comment_author_name2",
"text": "comment text",
"date": ISODate("date")
},
...
]
}
到目前为止一切顺利。
如果author_of_the_post
不更改他的名字(不考虑个人资料图片和描述),一切正常。
对于所有 comment_authors
都是如此。
因此,如果我想考虑这种情况,我必须使用关系:
"authorID": <author_of_the_post_id>,
帖子作者和
"authorID": <comment_author_id>,
评论作者。
但是MongoDB在查询时不允许连接。因此,每个 authorID
都会有不同的查询。
如果我的博文有 100 条评论,会发生什么情况?
1 query for the post
1 query to retrieve authors informations
100 queries to retrieve comments' authors informations
**total of 102 queries!!!**
我说得对吗?
这里使用noSQL的优势在哪里? 据我了解,102 个查询 VS 1 个使用联接的更大查询。
或者我错过了什么并且有不同的方法来模拟这种情况?
感谢您的贡献!
最佳答案
你见过这个吗?
http://www.sarahmei.com/blog/2013/11/11/why-you-should-never-use-mongodb/
听起来您正在做的事情对于 NoSQL 来说并不是一个好的用例。使用关系数据库进行基础数据存储来支持应用程序,使用NoSQL进行缓存等。
关于Mongodb真实基本用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22272379/