I'm trying to create a server where my webpage / app can make calls, from now I'm starting with Login so, I've created the Server according my needs, the problem is on application.properties
that I'm missing something, I have this :
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.authentication-database=mydatabase
spring.data.mongodb.username=stuart
spring.data.mongodb.password=stuartdto
spring.data.mongodb.database=mydatabase
And the error is this one when trying to call the login call
com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }
I've started mongod
using this command mongod --auth
and I've created an user to do this (is working because if I do manually mongo -u user -p 'password' --authenticationDatabase "admin"
works) it wasn't working until I add this --authenticationDatabase "admin"
so maybe that's what I need from Spring
.
What I'm missing?
It's Easy to Connect MongoDB Atlas with Spring Boot Through this article, we demonstrated that MongoDB Spring Boot integration is easy using: Starter data MongoDB artifactid (the dependency we added while creating the Spring Initializr project) in pom. xml. A property on application.
MongoDB and Spring Boot CRUD Examples To connect to MongoDB Atlas, we specify the connection string in the application. yaml file in the src/main/resources folder. The connection string for a cluster can be found in the Atlas UI. There is no need to write connection-related code in any other file.
If you are using spring.data.mongodb.uri
method,
spring.data.mongodb.uri=mongodb://stuart:stuartdto@localhost:27017/mydatabase?authSource=admin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With