我正在接近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":,
对于帖子的作者和
"authorID":,
评论作者.
但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更大的查询使用连接.
或者我错过了什么,有不同的方式来模拟这种情况?
谢谢你的贡献!