fix: add mongo ping detection

This commit is contained in:
luhaoling 2024-02-02 17:17:27 +08:00
parent e99577b21f
commit 68e29cd360

View File

@ -54,6 +54,9 @@ func NewMongo() (*Mongo, error) {
defer cancel()
mongoClient, err = mongo.Connect(ctx, options.Client().ApplyURI(uri))
if err == nil {
if err = mongoClient.Ping(ctx, nil); err != nil {
return nil, errs.Wrap(err, uri)
}
return &Mongo{db: mongoClient}, nil
}
if shouldRetry(err) {