我已经尝试使用驱动程序 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
}
}
Run Code Online (Sandbox Code Playgroud)
但显示错误:
不能使用 "github.com/mongodb/mongo-go-driver/mongo/options".Client().ApplyURI("mongodb://localhost:27017") (type *"github.com/mongodb/mongo-go- driver/mongo/options".ClientOptions) 作为类型 *"go.mongodb.org/mongo-driver/mongo/options".ClientOptions 在 mongo.NewClient 的参数中
驱动版本使用V1.0.0
任何建议?