基于nosql数据库的学生信息管理系统
时间: 2023-12-27 07:04:08 浏览: 34
基于NoSQL数据库的学生信息管理系统可以使用文档数据库或键值数据库来存储学生信息。下面是一个使用MongoDB作为文档数据库的示例:
```python
from pymongo import MongoClient
# 连接MongoDB数据库
client = MongoClient('mongodb://localhost:27017/')
db = client['student_db']
collection = db['students']
# 插入学生信息
student1 = {
'name': '张三',
'age': 20,
'major': '计算机科学',
'grades': {'math': 90, 'english': 85, 'history': 95}
}
student2 = {
'name': '李四',
'age': 21, 'major': '物理学',
'grades': {'math': 95, 'english': 80, 'history': 75}
}
collection.insert_many([student1, student2])
# 查询学生信息
result = collection.find({'major': '计算机科学'})
for student in result:
print(student)
# 更新学生信息
collection.update_one({'name': '张三'}, {'$set': {'age': 21}})
# 删除学生信息
collection.delete_one({'name': '李四'})
```
这个示例使用了MongoDB作为NoSQL数据库,通过连接数据库、插入、查询、更新和删除学生信息的操作来展示基于NoSQL数据库的学生信息管理系统。