Mongodb 每个数据库操作需要30秒

Mongodb 每个数据库操作需要30秒,mongodb,go,mongo-go-driver,Mongodb,Go,Mongo Go Driver,即使是最简单的代码: func main(){ ctx,cancel:=context.WithTimeout(context.Background(),10*time.Second) 推迟取消 client,err:=mongo.Connect(ctx,options.client().ApplyURI(“mongodb+srv://standard:example@cluster0.f5yec.mongodb.net/blog应用程序(retryWrites=true&w=mailty) 如

即使是最简单的代码:

func main(){
ctx,cancel:=context.WithTimeout(context.Background(),10*time.Second)
推迟取消
client,err:=mongo.Connect(ctx,options.client().ApplyURI(“mongodb+srv://standard:example@cluster0.f5yec.mongodb.net/blog应用程序(retryWrites=true&w=mailty)
如果错误!=零{
log.Fatal(“错误连接到数据库:”,err.Error())
}
db:=客户端数据库(“博客应用程序”)
fmt.Println(time.Now().Second())//9
db.Collection(“user”).Find(context.Background(),bson.M{})
fmt.Println(time.Now().Second())//39
}
运行需要30秒

为什么它需要这么长时间才能运行?
感谢您的帮助

检查查找时没有错误。查找失败,因为客户端无法连接到群集,默认服务器选择超时为30秒


“每个数据库操作需要30秒”只是部分正确。每次尝试数据库操作都需要30秒才能失败。

测量时间的方法是有缺陷的。我不是说它不是30秒,但根据输出,它也可以是1分30秒,或者1小时27分30秒,或者其他任何时间30秒。是的,但是当我运行它时,我注意到它需要30秒。