mongo-go-driver错误mongo.NewClient参数中的新客户端错误ClientOptions [英] Mongo-go-driver error New client error ClientOptions in argument to mongo.NewClient
问题描述
我已经尝试使用驱动程序mongodb来进行简单的连接,例如本回购协议中的教程 github mongo-go -driver 我只是这样写客户端:
i have try driver mongodb for a simple connection like on tutorial from this repos github mongo-go-driver i just write client like this :
import (
"fmt"
"github.com/mongodb/mongo-go-driver/mongo"
"github.com/mongodb/mongo-go-driver/mongo/options"
)
var client *mongo.Client
func main() {
fmt.Println("Starting the application...")
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://localhost:27017"))
if err != nil {
fmt.Println(err.Error())
return
}
}
但是显示错误:
不能使用"github.com/mongodb/mongo-go-driver/mongo/options".Client().ApplyURI("mongodb://localhost:27017")(类型*"github.com/mongodb/mongo -go-driver/mongo/options".ClientOptions),类型为*" go.mongodb.org/mongo-driver/mongo/options".mongo.newclient的参数中的ClientOptions
cannot use "github.com/mongodb/mongo-go-driver/mongo/options".Client().ApplyURI("mongodb://localhost:27017") (type *"github.com/mongodb/mongo-go-driver/mongo/options".ClientOptions) as type *"go.mongodb.org/mongo-driver/mongo/options".ClientOptions in argument to mongo.NewClient
驱动程序版本使用V1.0.0
Driver version use V1.0.0
有没有建议?
推荐答案
您不应使用github
版本的mongo驱动程序.它只是位于go.mongodb.org/mongo-driver/mongo
的repo的分叉.因此,首先放在go get go.mongodb.org/mongo-driver/mongo
位置,然后更改
you should not use github
version of mongo driver. It is just fork of repo located here go.mongodb.org/mongo-driver/mongo
. So in first place go get go.mongodb.org/mongo-driver/mongo
and then your improts you should change
github.com/mongodb/mongo-go-driver/*
到
go.mongodb.org/mongo-driver/*
这篇关于mongo-go-driver错误mongo.NewClient参数中的新客户端错误ClientOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!