Home  >  Article  >  Backend Development  >  python实现连接mongodb的方法

python实现连接mongodb的方法

WBOY
WBOYOriginal
2016-06-10 15:12:591095browse

本文实例讲述了python实现连接mongodb的方法。分享给大家供大家参考。具体分析如下:

通过pymongo可以很容易的链接到mongodb,下面的代码链接到本地mongodb,数据库为mydb,并检索出mycollection中的所有数据输出,简单的几行代码已经做了很多事情

from pymongo import Connection
connection = Connection(‘localhost', 27017) 
db = connection.mydb
collection = db.mycollection
for doc in collection.find():
  doc

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn