-2

I am trying to work on MongoDB gridfs and I am new to it. I found online resources to make the gridfs work in golang and I found this article. When I took the code and tried to run it, it gave me the following error.

Error

could not import go.mongodb.org/mongo-driver/mongo/gridfs (cannot find package "go.mongodb.org/mongo-driver/mongo/gridfs" in any of 
/usr/local/go/src/go.mongodb.org/mongo-driver/mongo/gridfs (from $GOROOT)
/home/bilal/go/src/go.mongodb.org/mongo-driver/mongo/gridfs (from $GOPATH))

Libraries

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/gridfs"
"go.mongodb.org/mongo-driver/mongo/options"

These four libraries have given me this error. But I gave just one error example.

Gregor Zurowski
  • 2,222
  • 2
  • 9
  • 15
  • 1
    Read and follow https://golang.org/doc/#getting-started on how to set up your project and use 3rd party libraries. Hint: Use modules. – Volker May 27 '21 at 06:58

1 Answers1

0

Seems like you haven't installed the dependencies properly.

First you need to set up your project with go mod init PROJECT-NAME as described in the referenced article.

Then you need to install the dependencies as outlined in the article you initially linked:

go get go.mongodb.org/mongo-driver/mongo
go get go.mongodb.org/mongo-driver/mongo/gridfs
Gregor Zurowski
  • 2,222
  • 2
  • 9
  • 15
  • I installed them but still giving me the errors. – subha bhaijan May 27 '21 at 06:30
  • Have you initialized your project using go mod init NAME as described in the [referenced article](https://www.mongodb.com/blog/post/quick-start-golang-mongodb-starting-and-setup)? Is `mongo-driver` referenced in your project's go.mod file? – Gregor Zurowski May 27 '21 at 07:01