spring-webflux-reactive-rest-api-demo
spring-webflux-reactive-rest-api-demo copied to clipboard
Access secure mongo db
My mongo data base like mongo --port 27017 -u "useradmin" -p "root" --authenticationDatabase "admin"
and i set my properties like this spring.data.mongodb.uri=mongodb://localhost:27017/admin spring.data.mongodb.username= useradmin spring.data.mongodb.password= root
But i am not connect connection can you solve it...
@arjundevrana Please use the username & password in the connection uri like this -
spring.data.mongodb.uri=mongodb://useradmin:root@localhost:27017/admin
I've tried this and it's working. Spring Boot MongoDB properties are slightly confusing in this regard. The documentation says -
spring.data.mongodb.uri=mongodb://localhost/test # Mongo database URI. Cannot be set with host, port, and credentials.
(That means you have to specify username and password in the URI. They can't be set from username and password properties)
If you want to use username and password properties then make sure that you set host, port and database properties as well like this -
spring.data.mongodb.host=localhost # This is the deault
spring.data.mongodb.port=27017 # This is the default
spring.data.mongodb.username=useradmin
spring.data.mongodb.password=root
spring.data.mongodb.database=admin
Cheers, Rajeev
Thanks sir it is working