[GODRIVER-1145] Go Docker auth Created: 17/Jun/19  Updated: 27/Oct/23  Resolved: 20/Jun/19

Status: Closed
Project: Go Driver
Component/s: Authentication
Affects Version/s: 1.0.3
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Bailey Matthews Assignee: Emmanuel Eppinger (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Docker / Linux



 Description   

Lets say I have this code, with `mongodb` being the name of the docker link allowing me to connect:

  // Set client options
  clientOptions := options.Client().ApplyURI("mongodb:20930")
 
  // Connect to MongoDB
  client, err := mongo.Connect(context.TODO(), clientOptions)

How would I connect to the database using a username and password?



 Comments   
Comment by Emmanuel Eppinger (Inactive) [ 20/Jun/19 ]

Hi Bailey,

You could do use

 

ApplyURI("mongodb://myUsername:D1fficultP%40ssw0rd@mongodb:20930")

If you have any more questions about forming URIs you can take a look at https://docs.mongodb.com/manual/reference/connection-string/ 

 

Thanks,

Emmanuel

Comment by Bailey Matthews [ 17/Jun/19 ]

EDIT:

ApplyURI("mongodb:20930")

Is

ApplyURI("mongodb://mongodb:20930")

Generated at Thu Feb 08 08:35:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.