supercharge / mongodb-github-action

Use MongoDB in GitHub Actions
MIT License
222 stars 46 forks source link

Cannot connect to mongodb from Springboot #43

Closed ckmoga closed 1 year ago

ckmoga commented 1 year ago

I have successfully created mongo instance but authentication fails while connecting from Springboot application.

workflow

- name: Start MongoDB
  uses: supercharge/mongodb-github-action@1.8.0
  with:
    mongodb-version: 6.0
    mongodb-username: username
    mongodb-password: password
    mongodb-db: newDb

application properties

spring.config.activate.on-profile: dev
spring.data.mongodb.host: localhost
spring.data.mongodb.port: 27017
spring.data.mongodb.username: username
spring.data.mongodb.password: password
spring.data.mongodb.database: newDb

I can see the server is started

Starting single-node instance, no replica set
    - port [270[17](<hidden>/actions/runs/3919232349/jobs/6700104841#step:5:19)]
    - version [6]
    - database [newDb]
    - credentials [username:password]

Error log

org.springframework.data.mongodb.UncategorizedMongoDbException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='username', source='newDb', *** mechanismProperties=<hidden>}; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='username', source='newDb', *** mechanismProperties=<hidden>}
  Caused by: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='username', source='newDb', *** mechanismProperties=<hidden>}
  Caused by: 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"}
ckmoga commented 1 year ago

Fixed by changing uri to: spring.data.mongodb.uri: mongodb://username:password@127.0.0.1:27017

marcuspoehls commented 1 year ago

@ckmoga Hey Charles, great you solved your issue, and thank you for sharing your solution!