MongoDB学习笔记

from pymongo import MongoClient

# 连接数据库
client = MongoClient("localhost", 27017)
# 获取数据库
db = client["Students"]
# 获取集合
students_collections = db["StudentsTable"]
# books_collections = db["books_info"]

# 查询students记录
# for i in students_collections.find():
#     print(i)
# for i in students_collections.find({"age":{"$gte":5}}):
#     print(i)

# 插入记录
# students = [
#     {"姓名": "张三", "学号": "2020123456", "专业": "计算机科学", "年级": "大二", "联系方式": "zhangsan@example.com"},
#     {"姓名": "李四", "学号": "2020123457", "专业": "电子工程", "年级": "大一", "联系方式": "lisi@example.com"},
#     {"姓名": "王五", "学号": "2020123458", "专业": "软件工程", "年级": "大三", "联系方式": "wangwu@example.com"},
#     {"姓名": "赵六", "学号": "2020123459", "专业": "信息管理", "年级": "大四", "联系方式": "zhaoliu@example.com"}]
# students_collections.insert_many(students)
for i in students_collections.find():
    print(i)

# 删除记录
# res=students_collections.delete_one({"name":"liu","age":"18"})
# print(res.deleted_count,res)

# 修改记录
# res=books_collections.update_one({"author": "Mike"}, {"$set": {"text": "Updated text."}})
# print(res)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值