Heim  >  Artikel  >  Backend-Entwicklung  >  python实现连接mongodb的方法

python实现连接mongodb的方法

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

本文实例讲述了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程序设计有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn