游戏装备数据、直播数据、打赏数据、物联网数据:修改频率极高
1.下载mongodb安装包
链接:https://pan.baidu.com/s/19opeIWKGSpEoRe6dFxIKLA
提取码:q73r
2.创建data/db文件
3.bin目录下cmd输入 mongod --dbpath E:\mongoDB\data\db
,首次安装需执行两次,命令窗口中打印一些启动信息,则表示启动成功。如下所示:
4.在浏览器中输入http://localhost:27017/即可看到显示信息为:
It looks like you are trying to access MongoDB over HTTP on the native driver port.
5.安装robo3t----版本需要与mongodb版本对应
链接:https://pan.baidu.com/s/1XzzszwVJaaI5j_yES3b-Qg
提取码:05g1
6.连接mongodb ------首次连接需要重启mongodb
若缺失dll文件,下载对应dll文件,拷贝至system32目录中
执行
regsvr32 vcruntime140_1.dll
创建springboot工程,选择mongodb依赖,其中pom文件如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
</parent>
<groupId>com.atheima</groupId>
<artifactId>springboot_17_mongodb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
yml配置文件配置:
spring:
data:
mongodb:
uri: mongodb://localhost/itheima
测试用例:
@SpringBootTest
class Springboot17MongodbApplicationTests {
@Autowired
private MongoTemplate mongoTemplate;
@Test
void test() {
Book book = new Book();
book.setId(1);
book.setName("springboot");
book.setType("springboot");
book.setDescription("springboot");
mongoTemplate.save(book);
}
}
Robo 3T:查询成功
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)