摘要
本实验报告聚焦于"大数据技术原理"课程中的NoSQL数据库实验。实验环境包括MySQL、Redis、MongoDB、Java以及Hadoop。实验内容涉及Redis和MongoDB的安装、配置和基本操作,包括数据的插入、删除和查询。此外,实验还包括使用Java API对MongoDB进行访问和操作。
在Redis部分,实验详细记录了从下载、安装到通过命令行与Redis交互的全过程。在MongoDB部分,实验不仅涵盖了MongoDB的安装和基本Shell命令的使用,还包括了使用Java API与MongoDB交互的实践。实验中遇到的问题包括键值对的选择、中文字符处理以及MongoDB版本和集合管理等,这些问题均通过相应的解决方案得到妥善处理。
总体强调了Redis作为缓存数据库的优势,以及MongoDB作为文档型NoSQL数据库的特点。Redis以其快速的读取速度和高效的运行效率著称,而MongoDB以其灵活的模式和丰富的查询语言为开发者提供了强大的数据处理能力。
关键词:NoSQL数据库;Redis;MongoDB;Java API;大数据技术
一.实验环境:
- MySQL
- Redis
- MongDB
- JAVA和Hadoop
二.实验内容与完成情况:
Redis的安装和使用。完成数据库的插入,删除,以及查询:
1.下载到对应文件夹:

2.输入命令安装redis:

3.打开redis服务器:

4.进入redis客户端:

5.使用键值对:

6.创建表:

7.插入数据:

8.删除数据:

MongoDB的安装和使用。完成MongoDB的基本的shell命令
1.使用软件源安装MongoDB:

2.创建MongoDB文件列表:

3.安装MongoDB:




4.启动MongoDB:

5.shell命令:

6.常见命令:
展现数据库、使用数据库、创建集合

7.插入数据:

8.查询所有记录:

9.查询指定记录:

10.查询指定列、sname、sage数据:

11.and条件查询:

12.or条件查询:

13.修改数据:

14. 删除数据:

使用Java API对MongoDB进行访问
1.将下载之后的jar包导入并且创建工程之后,在新建立的工程之下创建MongoDBExample.java文件:

2.代码:




3.结果:

三.出现的问题及解决方案:
1.使用redis数据库的时候,需要注意键值对的选择,注意,使用中文的时候可能会导致发生数据错误。
2.使用MongoDB的时候,注意对应的版本号,切换集合的时候,需要注意集合是否存在。
四.总结:
redis是NOSQL,即非关系型数据库,也是缓存数据库,即将数据存储在缓存中,缓存的读取速度快,能够大大的提高运行效率,但是保存时间有限。MongoDB是非关系型数据库(nosql ),属于文档型数据库。文档是MongoDB中数据的基本单元,类似关系数据库的行,多个键值对有序地放置在一起便是文档,语法有点类似javascript面向对象的查询语言,它是一个面向集合的,模式自由的文档型数据库。