如何在MongoDB GridFS中导入库?

huangapple go评论79阅读模式
英文:

How to import the libraries in mongodb gridfs?

问题

我正在尝试使用MongoDB的GridFS,并且对此还不太熟悉。我找到了一些在线资源,可以在Golang中使用GridFS,其中包括这篇文章。当我拿到代码并尝试运行时,出现了以下错误。

错误信息

无法导入 go.mongodb.org/mongo-driver/mongo/gridfs 包(无法在以下任何路径中找到包 "go.mongodb.org/mongo-driver/mongo/gridfs":
/usr/local/go/src/go.mongodb.org/mongo-driver/mongo/gridfs(来自 $GOROOT)
/home/bilal/go/src/go.mongodb.org/mongo-driver/mongo/gridfs(来自 $GOPATH))

"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"

这四个库给我带来了这个错误。但我只给出了一个错误示例。

英文:

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.

答案1

得分: 0

看起来你没有正确安装依赖项。

首先,你需要按照参考文章中描述的方式设置你的项目,使用go mod init 项目名称

然后,你需要按照你最初提供的文章中的说明安装依赖项:

go get go.mongodb.org/mongo-driver/mongo
go get go.mongodb.org/mongo-driver/mongo/gridfs
英文:

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

huangapple
  • 本文由 发表于 2021年5月27日 13:31:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/67716194.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定