title: Mongo-Go-Driver Failing to Connect
body: <p>So I am trying to use <a href="https://github.com/mongodb/mongo-go-driver" rel="nofollow noreferrer">https://github.com/mongodb/mongo-go-driver</a> to connect to a mongo database in golang.</p>
  
  <p>Here is my connection handler: </p>
  
  <pre><code>var DB *mongo.Database
  
  func CreateConnectionHandler()(*mongo.Database, error){
      fmt.Println("inside createConnection in database package")
      godotenv.Load()
      fmt.Println("in CreateConnectionHandler and SERVER_CONFIG: ")
      fmt.Println(os.Getenv("SERVER_CONFIG"))
      uri:=""
      if os.Getenv("SERVER_CONFIG")=="kubernetes"{
          fmt.Println("inside kubernetes db config")
          uri = "mongodb://patientplatypus:SUPERSECRETPASSDOOT@
                 mongo-release-mongodb.default.svc.cluster.local:27017/
                 platypusNEST?authMechanism=SCRAM-SHA-1"
      }else if os.Getenv("SERVER_CONFIG")=="compose"{
          fmt.Println("inside compose db config")
          uri = "mongodb://datastore:27017"
      }
      ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
      client, err := mongo.Connect(ctx, uri)
      if err != nil {
          return nil, fmt.Errorf("mongo client couldn't connect: %v", err)
      }
      DB := client.Database("platypusNEST")
      return DB, nil
  }
  </code></pre>
  
  <p>And the error I am getting: </p>
  
  <pre><code>api         | database/connection.go:29:30: cannot use uri (type 
  string) as type *options.ClientOptions in argument to mongo.Connect
  </code></pre>
  
  <p>So I tried replacing <code>uri</code> with the connection string like this: </p>
  
  <pre><code>client, err := mongo.Connect(ctx, "mongodb://datastore:27017")
  </code></pre>
  
  <p>But I still got the error.</p>
  
  <p>Compare this with what is in the documentation: </p>
  
  <blockquote>
  <pre><code>ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
  client, err := mongo.Connect(ctx, "mongodb://localhost:27017")
  </code></pre>
  </blockquote>
  
  <p>And it is exactly the same! I'm really not sure why there is this error. Any ideas?</p>