英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论