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'])

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

小兜全糖(Cx) 发布了88 篇原创文章 · 获赞 10 · 访问量 1万+ 私信 关注

相关文章

MongoTemplate 是Spring Data MongoDB 中的一个核心类,为 S...
笔者今天要分享的是一个项目重构过程中如何将数据库选型由原...
mongodb/mongoTemplate.upsert批量插入更新数据的实现
进入官网下载官网安装点击next勾选同意,点击next点击custom...
头歌 MongoDB实验——数据库基本操作
期末考试复习总结