spring-webflux-reactive-rest-api-demo icon indicating copy to clipboard operation
spring-webflux-reactive-rest-api-demo copied to clipboard

Access secure mongo db

Open arjundevrana opened this issue 7 years ago • 3 comments

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 avatar Dec 17 '17 05:12 arjundevrana

@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)

callicoder avatar Dec 17 '17 06:12 callicoder

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

callicoder avatar Dec 17 '17 06:12 callicoder

Thanks sir it is working

arjundevrana avatar Dec 17 '17 18:12 arjundevrana