-1

I am getting following exception when I run spring boot mongo db project using java

com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='rootuser', source='admin', password= , mechanismProperties= }

below my application.properties

spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=rootuser
spring.data.mongodb.password=rootpass
spring.data.mongodb.database=amigoscode
spring.data.mongodb.port=27017
spring.data.mongodb.host=localhost
spring.data.mongodb.uri=mongodb://rootuser:rootpass@localhost:27017/amigoscode?authSource=admin

even I have tried all answers from stackoverflow answers and from internet as well I have tried following answer as well AuthenticationFailed to mongoDB with Spring boot I want to know where I am making mistake

below my docker-compose.yaml

version: "3.8"
services:
  mongodb:
    image: mongo
    container_name: mongodb
    ports:
      - 27017:27017
    volumes:
      - data:/data
    environment:
      - MONGO_INITDB_ROOT_USERNAME=rootuser
      - MONGO_INITDB_ROOT_PASSWORD=rootpass
  mongo-express:
    image: mongo-express
    container_name: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=rootuser
      - ME_CONFIG_MONGODB_ADMINPASSWORD=rootpass
      - ME_CONFIG_MONGODB_SERVER=mongodb
      - ME_CONFIG_MONGODB_URL"mongodb://root:rootpass@mongo:27017/"
volumes:
  data: {}

networks:
  default:
    name: mongodb_network
Edgar
  • 860
  • 1
  • 17
  • 38
  • Does the username or password contain any of `: / ? # [ ] @`? If so, [they need to be _percent encoded_](https://www.mongodb.com/docs/manual/reference/connection-string/). – rickhg12hs Aug 11 '23 at 13:25
  • @rickhg12hs I have tried your suggestion it is not working – Edgar Aug 12 '23 at 07:36
  • Perhaps you could look at the MongoDB server log, `mongod.log`, for more information? And, is that the full error message? Do you know the line of code where the error happens? Would you show your code that attempts to connect/authenticate? – rickhg12hs Aug 12 '23 at 14:20
  • @rickhg12hs I have added docker-compose.yaml file please check it I have done all steps which asked even I followed this tutorial as well https://www.baeldung.com/spring-data-mongodb-connection – Edgar Aug 13 '23 at 16:22
  • Did you look in `mongod.log`? If there is an error or a fail, sometimes it even has instructions for a fix. – rickhg12hs Aug 13 '23 at 19:38

0 Answers0