首页 > 代码库 > python如何通过pymongo连接到mongodb?

python如何通过pymongo连接到mongodb?

python版本2.7,mongodb2.6.9,pymongo

首先在mongodb中创建一个数据库users,然后连接到users

from pymongo import MongoClient
mc=MongoClient("localhost",27017)
db=mc.users
db.users.save({"name":"me","age":"23"})
c=db.users.find()
for o in c:
print(o)

python如何通过pymongo连接到mongodb?