Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access secure mongo db #2

Open
arjundevrana opened this issue Dec 17, 2017 · 3 comments
Open

Access secure mongo db #2

arjundevrana opened this issue Dec 17, 2017 · 3 comments

Comments

@arjundevrana
Copy link

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...

@callicoder
Copy link
Owner

callicoder commented Dec 17, 2017

@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
Copy link
Owner

callicoder commented Dec 17, 2017

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

@arjundevrana
Copy link
Author

Thanks sir it is working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants