<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
下载方式
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-os-x/
docker 方式
docker pull mongodb/mongodb-community-server
下载方式 打开mongo command
mongosh
创建新库& 用户
use mongodbtest
db.createUser({
user: "admin",
pwd: "admin",
roles: [ { role: "readWrite", db: "mongodbtest" } ],
mechanisms : ["SCRAM-SHA-1"]
})
mongodbtest> show collections
wordPage1
mongodbtest> db.wordPage1.find()
[
{
_id: '1000',
name: 'zhangsan',
age: '10',
isNice: true,
isLucky: true,
comment: '测试'
},
{
_id: '1001',
name: 'li4',
age: '12',
isNice: false,
isLucky: true,
comment: '测试2'
}
]
mongodbtest>
github
https://github.com/moocstudent/springboot-mongodb-demo