[GODRIVER-849] (type *"project/vendor/go.mongodb.org/mongo-driver/mongo/options".ClientOptions has no field or method ApplyURI) Created: 25/Feb/19  Updated: 11/Sep/19  Resolved: 04/Mar/19

Status: Closed
Project: Go Driver
Component/s: Connections, Options & Configuration
Affects Version/s: 0.3.0
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: abhaygawade Assignee: Isabella Siu (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS: Windows 10
Go version: 1.11.5 windows/amd64



 Description   

I am getting below error while building my Go code:

.\main.go:23:52: "xp/gomongo/vendor/go.mongodb.org/mongo-driver/mongo/options".Client().ApplyURI undefined (type *"xp/gomongo/vendor/go.mongodb.org/mongo-driver/mongo/options".ClientOptions has no field or method ApplyURI

 

I have installed mongodb driver using dep as mentioned currently on  

main.go -->
package main

import (
    "context"
    "fmt"
    "log"
    "net/http"
    "time"

    "github.com/mongodb/mongo-go-driver/bson"
    "go.mongodb.org/mongo-driver/mongo"
    "go.mongodb.org/mongo-driver/mongo/options"
)

func rootHandler(w http.ResponseWriter, r *http.Request)

{     fmt.Fprintln(w, "Its Started...") }

func main()

{     fmt.Println("Welcome!")     ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)     client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))     collection := client.Database("xpdb").Collection("users")     res, err := collection.InsertOne(ctx, bson.M\{"name": "Abhay", "place": "Sawantwadi"}

)

    http.HandleFunc("/", rootHandler)
    log.Fatal(http.ListenAndServe(":8080", nil))
}



 Comments   
Comment by Isabella Siu (Inactive) [ 26/Feb/19 ]

Hi abhaygawade,

dep places 0.3.0 ahead of 1.0.0-rc1 when picking an update version. To choose 1.0.0-rc1, the dep ensure command should be run as:

dep ensure -add go.mongodb.org/mongo-driver/mongo@1.0.0-rc1

Comment by abhaygawade [ 26/Feb/19 ]

Thanks isabella.siu,

This means the initial dep ensure -add go.mongodb.org/mongo-driver should give latest version 1.0.0-rc1 instead of 0.3.0

We are good to close this issue if latest version of driver is coming through dep.

Comment by Isabella Siu (Inactive) [ 25/Feb/19 ]

Hi abhaygawade,

The NewClient argument were changed between versions 0.3.0 and 1.0.0-rc1, so to use this syntax you should update the version constraint for go.mongodb.org/mongo-driver in your Gopkg.toml to "v1.0.0-rc1", and run "dep ensure -update go.mongodb.org/mongo-driver" to update the version.

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