MongoDB 和“连接" [英] MongoDB and "joins"

查看:28
本文介绍了MongoDB 和“连接"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定 MongoDB 不正式支持加入".这是什么意思?

I'm sure MongoDB doesn't officially support "joins". What does this mean?

这是否意味着我们不能将两个集合(表)连接在一起."?

Does this mean "We cannot connect two collections(tables) together."?

我想如果我们把集合 A 中 _id 的值放到集合 B 中的 other_id 上,我们可以简单地连接两个集合吗?

I think if we put the value for _id in collection A to the other_id in collection B, can we simply connect two collections?

如果我的理解是正确的,MongoDB 可以将两个表连接在一起,例如,当我们运行查询时.这是由 http://www.mongodb.org/display/中的参考"完成的DOCS/架构+设计.

If my understanding is correct, MongoDB can connect two tables together, say, when we run a query. This is done by "Reference" written in http://www.mongodb.org/display/DOCS/Schema+Design.

那么加入"的真正含义是什么?

Then what does "joins" really mean?

我很想知道答案,因为这对于学习 MongoDB 模式设计至关重要.http://www.mongodb.org/display/DOCS/Schema+Design

I'd love to know the answer because this is essential to learn MongoDB schema design. http://www.mongodb.org/display/DOCS/Schema+Design

推荐答案

它不是连接,因为只有在需要时才会评估关系.另一方面,连接(在 SQL 数据库中)将解析关系并将它们作为单个表返回(您将两个表合并为一个").

It's no join since the relationship will only be evaluated when needed. A join (in a SQL database) on the other hand will resolve relationships and return them as if they were a single table (you "join two tables into one").

您可以在此处阅读有关 DBRef 的更多信息:http://docs.mongodb.org/manual/applications/database-references/

You can read more about DBRef here: http://docs.mongodb.org/manual/applications/database-references/

解析引用有两种可能的解决方案.一种是手动完成,正如您几乎描述的那样.只需将一个文档的_id保存在另一个文档的other_id中,然后自己编写函数来解决关系.另一种解决方案是使用上面手册页中描述的 DBRefs,这将使 MongoDB 按需解析关系客户端.您选择哪种解决方案并不重要,因为这两种方法都会在客户端解析关系(请注意,SQL 数据库在服务器端解析连接).

There are two possible solutions for resolving references. One is to do it manually, as you have almost described. Just save a document's _id in another document's other_id, then write your own function to resolve the relationship. The other solution is to use DBRefs as described on the manual page above, which will make MongoDB resolve the relationship client-side on demand. Which solution you choose does not matter so much because both methods will resolve the relationship client-side (note that a SQL database resolves joins on the server-side).

这篇关于MongoDB 和“连接"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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