如何导入 mongodb gridfs 中的库?

How to import the libraries in mongodb gridfs?

我正在尝试使用 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"

这四个库都给我这个错误。但是我只举了一个错误的例子。

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

首先,您需要使用 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