python MongoDB

MongoDB官网下载地址
https://www.mongodb.com/download-center/community
1 连接
安装pymongo

pip install pymongo

连接MongoDB

from pymongo import MongoClient
conn=MongoClient('localhost',27017)
db=conn.Student
table=db.student
#删除所有age大于10的数据
table.delete_many({"age":{"$gt":10}})
stu=[{"name":"1","age":30},{"name":"2","age":30},{"name":"3","age":30},{"name":"4","age":30}]
table.insert_many(stu)
table.insert_one({"name":"chen","age":29})
table.update_one({"name":"chen"},{"$set":{"name":"chenxu","age":29}},upsert=True)

for i in table.find():
    print(i['name'])

后续会继续更新,先占个坑,敦促自己

python MongoDBpython MongoDB 小兜全糖(Cx) 发布了88 篇原创文章 · 获赞 10 · 访问量 1万+ 私信 关注
上一篇:数据存储之非关系型数据库存储----MongoDB存储


下一篇:pymongo 删除数据相关