SpringBoot 之集成 MongoDB
# SpringBoot 之集成 MongoDB
# 配置 mongodb
# 创建 admin
use admin
db.createUser({
"user": "admin",
"pwd": "123456",
"roles": [{ "role": "userAdminAnyDatabase", "db": "admin" }]
})
# 创建 root
db.createUser({
"user": "root",
"pwd": "123456",
"roles": [{ "role": "root", "db": "admin" }]
})
# 创建用户自己的数据库的角色
use test
db.createUser({
"user": "test",
"pwd": "123456",
"roles": [{ "role": "dbOwner", "db": "test" }]
})
# 查看用户
db.system.users.find()
show users
# 删除用户
删除用户必须由账号管理员来删,所以,切换到 admin 角色
use admin
db.auth("admin","123456")
# 删除单个用户
db.system.users.remove({user:"XXXXXX"})
# 删除所有用户
db.system.users.remove({})
# Spring Boot 配置
spring.data.mongodb.host = localhost
spring.data.mongodb.port = 27017
spring.data.mongodb.database = test
spring.data.mongodb.username = root
spring.data.mongodb.password = root
# 引用和引申
https://spring.io/guides/gs/accessing-data-mongodb/
📝 帮助改善此页面! (opens new window)
上次更新: 2024/01/27, 23:16:10