如何在Python中加入MongoDB集合? [英] How to join MongoDB collections in Python?

查看:142
本文介绍了如何在Python中加入MongoDB集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Python中联接两个MongoDB集合(从SQL来看是INNER JOIN)?我需要使用本机map/reduce javascript代码还是在PyMongo中执行此操作?如何用更少的代码解决这个问题?

How to join ( in a sense of INNER JOIN from SQL ) two MongoDB collections in Python ? Do I need to use native map/reduce javascript code or to do this in PyMongo ? How to solve this with less code ?

推荐答案

Mongo与传统关系数据库中存储数据的方式不同,并且不支持表联接,因为它可能在SQL数据库中使用.在数据库参考"文档中对此有一个注释. http://www.mongodb.org/display/DOCS/Database+References

Mongo stores data differently than in a traditional relational database, and does not support table joins as one might be used to in a SQL database. There is a note on this in the "Database References" documentation. http://www.mongodb.org/display/DOCS/Database+References

如果可能的话,最好将所有数据存储在一个集合中.如果无法做到这一点,则必须对所有数据库执行单独的查询,并以编程方式合并数据.

If possible, it is preferable to store all data in a single collection. If this is not possible, separate queries will have to be performed on all of the databases, and the data merged programmatically.

根据文档,可以将文档直接链接或与数据库引用链接到单独的集合中.仍然必须对每个集合执行单独的查询.

As per the documentation, it is possible to link documents in separate collections, either directly or with db references. Separate queries will still have to be performed on each collection.

以前也曾问过类似的问题. (我在下面提供了一些链接.)希望这些答复可以使您对MongoDB中的数据存储方式以及如何重组文档和/或查询有更多的了解,从而可以最少地检索所需的数据.对数据库的请求数.

Similar questions have been asked before. (I have included some links below.) Hopefully the responses will give you some additional insight into how data is stored in MongoDB, and how you can restructure your documents and/or queries such that you can retrieve the data that you need with the fewest number of requests to the database.

祝你好运!

MongoDB和"joins"

如何在MongoDB?

如何在mongodb中加入查询?

关于加入的初学者问题" http://groups.google.com/group/mongodb-user /browse_thread/thread/edfcf8bd270274f9/

"Beginner question regarding joins" http://groups.google.com/group/mongodb-user/browse_thread/thread/edfcf8bd270274f9/

这篇关于如何在Python中加入MongoDB集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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