我已经尝试了驱动程序mongodb作为一个简单的连接,就像这个repos github mongo-go-driver中的教程一样,我只是像这样写客户端:
import (
"fmt"
"github.com/mongodb/mongo-go-driver/mongo"
"github.com/mongodb/mongo-go-driver/mongo/options"
)
var client *mongo.Client
func main() {
fmt.Println("Starting the application...")
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://localhost:27017"))
if err != nil {
fmt.Println(err.Error())
return
}
}但显示错误:
无法使用"github.com/mongodb/mongo-go-driver/mongo/options".Client().ApplyURI("mongodb://localhost:27017") (将*"github.com/mongodb/mongo-go-driver/mongo/options".ClientOptions)类型作为mongo.NewClient的参数中的*"go.mongodb.org/mongo-driver/mongo/options".ClientOptions类型
驱动程序版本使用V1.0.0
有什么建议吗?
发布于 2019-03-14 16:36:08
您不应该使用github版本的mongo驱动程序。它只是位于这里go.mongodb.org/mongo-driver/mongo的repo的分支。所以首先是go get go.mongodb.org/mongo-driver/mongo,然后是你的即兴表演
github.com/mongodb/mongo-go-driver/*
至
go.mongodb.org/mongo-driver/*
https://stackoverflow.com/questions/55157890
复制相似问题