MongoDB和"joins" [英] MongoDB and "joins"

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

问题描述

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

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/Schema + Design .

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.

那么"joins"到底是什么意思?

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中,然后编写自己的函数即可解决该关系.另一个解决方案是使用上面手册页中所述的DBRef,这将使MongoDB根据需要解决 client-side 关系.选择哪种解决方案并不重要,因为这两种方法都可以解决客户端的关系(请注意,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和"joins"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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