I have recently noticed that the Spring Boot app does not provide the ability to run on local machine - I’d like to be able to do this. So, I have set up a Docker container, with a MongoDB instance.
Next, I want to override application.yaml, with a file called application-local.yaml. From here, I want to set up configuration properties for the MongoDB instance running in my Docker container. But I am not sure how to override the iam property - I will not connect to mongoDB in my local Docker container using iam, but I will get this property in application-local.yaml unless I specifically override it.
Can anyone provide advice on how this might be achieved, please?
Having spent considerable time on this issue, I have managed to make progress. The config in my initial post relates to a Bean, which I have now configured so that it is not used in LOCAL environment.
Now, I have the following in application-local.yaml:
When I run the Spring Boot application (NOT in Docker), I get the following error: com.mongodb.MongoQueryException: Command failed with error 13 (Unauthorized): 'Command find requires authentication' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Command find requires authentication", "code": 13, "codeName": "Unauthorized"}
This suggests, to me, that the Spring Boot application, running on my local machine, is actually connecting to MongoDB, running in Docker. Hope I am right about that!
So I am hoping someone can help with how to overcome the authorization issue that is preventing me from running a find command.
Any advice would be gratefully received - Thank you.
With a lot of trial and error, I managed to successfully persist a document in LOCAL environment.
By way of a reminder, I have a Spring Boot app, which is running on my local machine and the goal is to write a record to MongoDB, hosted within a Docker Container, also on my local machine.
Just to add some context in case anyone else finds this thread: the error you saw earlier (Command find requires authentication) is usually a sign that MongoDB is expecting credentials, but either they weren’t passed in or didn’t match. In your initial application-local.yaml, the URI didn’t include the username and password, so even though your Spring Boot app was connecting to MongoDB, it couldn’t authenticate.
Once you have updated the URI to include the credentials like this:
mongodb://:@localhost:27017/
It allowed the app to connect and perform operations as expected.
As an alternative for local development, some people choose to disable authentication entirely in their Docker MongoDB setup to avoid dealing with credentials. This can be done by adding a command: [“–noauth”] line in the docker-compose.yaml, but it’s only recommended for quick testing or local-only setups, not something you’d want in a shared or production environment.