进入虚拟环境
sudo pip install pymongo
或源码安装
python setup.py
import pymongo
client=pymongo.MongoClient("localhost", 27017)
或者
client=pymongo.MongoClient('mongodb://用户名:密码@ip地址:端口号/数据库名')
db=client.test1
stu = db.stu
s1={name:'gj',age:18}
s1_id = stu.insert_one(s1).inserted_id
s1={name:'gj',age:18}
s1_id = stu.update_one(s1, {'$set':{'name':'abc'}})
s1={name:'gj',age:18}
s1_id = stu.delete_one(s1)
s2=stu.find_one()
for cur in stu.find():
print cur
cur=stu.find()
cur.next()
cur.next()
cur.next()
print stu.count()