douchensou6495 2019-03-24 18:17
浏览 691
已采纳

如何导入官方的mongodb驱动程序包

How to import official mongoDB driver package in Go?

I am following the official Go-mongoDB-driver package instruction (https://www.mongodb.com/blog/post/mongodb-go-driver-tutorial). I have installed the mongoDB package using this:

go get github.com/mongodb/mongo-go-driver

but I just can't import the package

I am doing a very simple snippet in my main.go

package main

import "github.com/mongodb/mongo-go-driver/mongo

func main() {
}

This gives me:

main.go:8:8: code in directory $GOPATH/src/github.com/mongodb/mongo-go-driver/bson expects import "go.mongodb.org/mongo-driver/bson"

When I tried to import go.mongodb.org/mongo-driver/bson, It gives me this:

main.go:10:8: cannot find package "go.mongodb.org/mongo-driver/bson" in any of:
    /usr/local/go/src/go.mongodb.org/mongo-driver/bson (from $GOROOT)
    $GOPATH/src/go.mongodb.org/mongo-driver/bson (from $GOPATH)

Kindly help, quite new in Go and not sure where to look since I don't find people having this issue a lot.

  • 写回答

1条回答 默认 最新

  • doubai9014 2019-03-24 18:24
    关注

    The error actually gives you the answer: You must use that driver as go.mongodb.org/mongo-driver/bson instead. The package has apparently changed URLs some time in the past, and the tutorial you're referring to has not yet been updated.

    You should instead refer to the installation instructions here. In short, do this:

    go get go.mongodb.org/mongo-driver/mongo
    

    then import it using the same path:

    import (
        "go.mongodb.org/mongo-driver/mongo"
        "go.mongodb.org/mongo-driver/bson"
        // etc
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog