【问题标题】:How to import the libraries in mongodb gridfs?如何在 mongodb gridfs 中导入库?
【发布时间】:2021-05-27 20:54:03
【问题描述】:

我正在尝试使用 MongoDB gridfs,但我是新手。我找到了使 gridfs 在 golang 中工作的在线资源,我发现了这个article。当我拿到代码并尝试运行它时,它给了我以下错误。

错误

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

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

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

【问题讨论】:

标签: mongodb go go-modules


【解决方案1】:

好像你没有正确安装依赖项。

首先您需要使用go mod init PROJECT-NAME 设置您的项目,如referenced article 中所述。

然后你需要按照in the article you initially linked 的描述安装依赖项:

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

【讨论】:

  • 我安装了它们,但仍然给我错误。
  • 您是否按照referenced article 中的说明使用 go mod init NAME 初始化了您的项目?项目的 go.mod 文件中是否引用了 mongo-driver
猜你喜欢
  • 2015-03-04
  • 1970-01-01
  • 2015-08-22
  • 2014-04-28
  • 2012-04-28
  • 2012-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多