i am trying to run go fiber mongo db example provided by line below :
https://github.com/gofiber/recipes/blob/master/mongodb
and i have dockerized the mongo like this :
mongo:
container_name: mongo
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: secret
ports:
- "27017:27017"
volumes:
- mongo:/data/db
and in my code i have this config right now :
// Database settings (insert your own database name and connection URI)
const dbName = "scrapping"
const mongoURI = "mongodb://root:secret@localhost:27017/" + dbName
// Connect configures the MongoDB client and initializes the database connection.
// Source: https://www.mongodb.com/blog/post/quick-start-golang--mongodb--starting-and-setup
func Connect() error {
client, err := mongo.NewClient(options.Client().ApplyURI(mongoURI))
if err != nil {
return err
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
err = client.Connect(ctx)
db := client.Database(dbName)
if err != nil {
return err
}
mg = MongoInstance{
Client: client,
Db: db,
}
return nil
}
but when i hit the http://127.0.0.1:3000/employee
url i get authentication error as below :
connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.