文章目录


在model中添加依赖,为什么在model中添加?因为会有映射的实体类MongoObject对应mongodb中的数据表对象:

1. 引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
2. 在yml中添加配置
spring:
data:
mongodb:
uri: mongodb://root:root@192.168.92.134:27017
database: douyin-red-book
3. 在启动类中开启mongodb
@EnableMongoRepositories

SpringBoot 整合MongoDB_实体类