启动mongo镜像
docker run --name mongo-container -d -P mongo
连接到容器内
docker exec -it eb sh
输入:mongo
输入:show dbs
输入:db.stats()
下载mongo客户端:https://robomongo.org/download
按ctrl+c 和 exit 退出容器,输入:docker ps
这里自动映射的端口为32768,打开Robo 3T,输入地址,点击test
在左侧就能看到库了
新建spring-boot项目,添加pom引用
<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-hateoas</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.pegdown/pegdown -->
<dependency>
<groupId>org.pegdown</groupId>
<artifactId>pegdown</artifactId>
<version>1.6.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>