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)

posted @ 2016-10-19 18:45  大斗神204  阅读(1109)  评论(0编辑  收藏  举报