mongo-go-driver错误mongo.NewClient参数中的新客户端错误ClientOptions [英] Mongo-go-driver error New client error ClientOptions in argument to mongo.NewClient

查看:357
本文介绍了mongo-go-driver错误mongo.NewClient参数中的新客户端错误ClientOptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试使用驱动程序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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆