2019-03-24 18:17
浏览 539


How to import official mongoDB driver package in Go?

I am following the official Go-mongoDB-driver package instruction ( I have installed the mongoDB package using this:

go get

but I just can't import the package

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

package main

import "

func main() {

This gives me:

main.go:8:8: code in directory $GOPATH/src/ expects import ""

When I tried to import, It gives me this:

main.go:10:8: cannot find package "" in any of:
    /usr/local/go/src/ (from $GOROOT)
    $GOPATH/src/ (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
    doubai9014 2019-03-24 18:24

    The error actually gives you the answer: You must use that driver as 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

    then import it using the same path:

    import (
        // etc
    点赞 评论