【大数据处理技术】实验4

本文详细介绍了在Ubuntu 22.04 LTS上安装MongoDB 5.0的步骤,包括更新系统、添加MongoDB源、安装服务包、启动MongoDB及验证状态。此外,还提供了MongoDBShell的操作示例,如创建数据库、插入数据、查询和更新学生信息。
摘要由CSDN通过智能技术生成
  • 安装MongoDB(Ubuntu版本:22.04 LTS)

0.查看Ubuntu版本

命令:lsb_release -a

1.使用Ubuntu命令安装

(1)更新系统包:

sudo apt update(可选)

sudo apt upgrade(可选)

sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common

(2)安装MongoDB的依赖libssl1.1(安装curl后使用curl命令安装)

 

(3)运行下命令将 MongoDB 存储库添加到的 Ubuntu 系统(可选?)

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

(4)添加MongoDB GPG密钥

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

(5)添加储存库,同时命令安装MongoDB服务包

sudo apt update

sudo apt install mongodb-org(sudo apt install -y mongodb-org)

2.启动MongoDB,验证状态

sudo systemctl enable mongod

sudo systemctl start mongod

sudo systemctl status mongod

3.测试MongoDB

mongo --eval 'db.runCommand({connectionStatus: 1})'

4.启动MongoDB Shell

mongo

  • 根据给出的Student文档完成操作

Student文档:

{

“name”: “zhangsan”,

“score”:{

“English”: 70,

“Math”: 80,

“Computer”: 90

}

}

{

“name”: “lisi”,

“score”: {

“English”: 30,

“Math”: 40,

“Computer”: 50

}

}

1.用 MongoDB Shell 设计出 Student 集合。

(1)创建数据库:(数据库名字改成自己的!)

Use database_liuhao

(2)创建集合:

db.createCollection(“Student”)

(3)插入数据:

db.Student.insert( name:”zhangsan”, score:{ English:70, Math:80, Computer:90 } })

db.Student.insert( name:”lisi”, score:{ English:30, Math:40, Computer:50 } })

2.用 find()方法输出两个学生的信息。

db.Student.find()

db.Student.find().pretty() //易读方式

3.用 find()方法查询 lisi 的所有成绩(只显示 score 列)。

db.Student.find({ name:”lisi” }, { score:1, _id:0 })

 

4.修改 zhangsan Math 成绩为 66

db.Student.update({name:”zhangsan”},{$set:{“score.Math”:66}})

MongoDB官网:MongoDB Documentation

MongoDB教程1:MongoDB 创建数据库_w3cschool

MongoDB教程2:MongoDB 教程 | 菜鸟教程

MongoDB嵌套修改:MongoDB 如何更新嵌套文档? - 知乎

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值