对数据操作:
1、用find指令浏览表的所有数据。
2、查询学号为95002 的所有信息。
3、删除姓名为liuchen的数据
4、将学号为95001的年龄改为22岁
5、插入数据
6、删除集合
7、 退出mongodb shell模式
8、关闭mongodb服务
例题一:

根据上面给出的表格,用MongoDB设计student学生表格。
首先我们启动****MongoDB,****分为两步:
1、进入MongoDB安装目录:
2、启动MongoDB:

输入pgrep mongo -l查看是否启动成功:

进入mongodb shell模式:

创建student数据库:
首先查看数据库:

其中并没有student数据库:
创建第一步:use student

创建第二步:
var stus=[
{"sno":"95001","name":"liyong","name":"boy","sage":"20","sdept":"CS"},
{"sno":"95002","name":"liuchen","name":"girl","sage":"19","sdept":"IS"},
{"sno":"95003","name":"wangmin","name":"girl","sage":"18","sdept":"MA"}
]
创建第三步:
db.student111:将上方数组插入到student111集合中,为区别数据库student,后面加上111

查看是否创建成功:
其中show collections意为查看集合,发现集合为student111
show dbs意为查看数据库,发现数据库中已经存在student

分析:创建第一步意为切换到student数据库,(虽然数据库中目前没有student,但是之后操作都是在对student操作)。创建第二步定义包含三条数据的数组;创建第三步意为将第二步的数组存放到student111集合中。而student111集合存在于student数据库中。最后查看数据库student已经存在。
对数据操作:
1、用find指令浏览表的所有数据。

















