Hi I'm new in Spring Boot and i have some problem ...
# spring
a
Hi I'm new in Spring Boot and i have some problem with mongo db connection. I used a composer to create mongo container and it works. I tryed to connect with a repository and API but all works without authentication. I put some code.
Composer
Copy code
version: '3.8'

services:
  mongodb:
    image: mongo:7.0
    container_name: mongodb
    restart: always
    ports:
      - "27017:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: password123
      MONGO_INITDB_DATABASE: mydb
    volumes:
      - mongodb_data:/data/db
      - mongodb_config:/data/configdb
    networks:
      - mongo-network

volumes:
  mongodb_data:
    driver: local
  mongodb_config:
    driver: local

networks:
  mongo-network:
    driver: bridge
I used this app properties:
Copy code
spring.data.mongodb.uri: <mongodb://admin:password123@localhost:27017/mydb?authSource=admin>

spring.data.mongodb.auto-index-creation= true
I receive this error:
by: com.mongodb.MongoCommandException: Command execution failed on MongoDB server with error 13 (Unauthorized): 'Command createIndexes requires authentication' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Command createIndexes requires authentication", "code": 13, "codeName": "Unauthorized"}
I create a version without authentication, i wrote in termina:
Copy code
docker stop mongodb
docker rm mongodb
docker run -d --name mongodb -p 27017:27017 mongo:7.0
and It works.. api work 😞