登录
首页 >  Golang >  Go问答

mongo-go-driver 中的 clientOptions 的默认值是什么?

来源:stackoverflow

时间:2024-03-04 16:18:21 267浏览 收藏

在Golang实战开发的过程中,我们经常会遇到一些这样那样的问题,然后要卡好半天,等问题解决了才发现原来一些细节知识点还是没有掌握好。今天golang学习网就整理分享《mongo-go-driver 中的 clientOptions 的默认值是什么?》,聊聊,希望可以帮助到正在努力赚钱的你。

问题内容

我试图搜索 mongo-go-driver 的 clientoptions 的默认值。

我正在尝试通过以下方式启动新客户端:

        opts := options.clientoptions{}
    opts.applyuri(connectionuri)
    sharedconnection, err = mongo.newclient(&opts)

我想知道一些 clientoptions(例如 connecttimeout、maxpoolsize、maxconnidletime)的默认值是什么。

   type ClientOptions struct {
    ConnectTimeout         *time.Duration
    Compressors            []string
    Dialer                 ContextDialer
    HeartbeatInterval      *time.Duration
    LocalThreshold         *time.Duration
    MaxConnIdleTime        *time.Duration
    MaxPoolSize            *uint16
    Monitor                *event.CommandMonitor
    ReadConcern            *readconcern.ReadConcern
    ReadPreference         *readpref.ReadPref
    Registry               *bsoncodec.Registry
    RetryWrites            *bool
    ServerSelectionTimeout *time.Duration
    Direct                 *bool
    SocketTimeout          *time.Duration
    TLSConfig              *tls.Config
    WriteConcern           *writeconcern.WriteConcern
    ZlibLevel              *int
   }

解决方案


以下默认基于 mongo-go-driver v1.1.x 和 mongodb 服务器 v4.2。您还可以在MongoDB driver specs上了解更多信息/行为。

ConnectTimeout         30 * time.Second
Compressors            nil (compression will not be used)
Dialer                 net.Dialer with a 300 second keepalive time
HeartbeatInterval      10 * time.Second
LocalThreshold         15 * time.Millisecond
MaxConnIdleTime        nil (no limit)
MaxPoolSize            100
Monitor                nil
ReadConcern            nil (server default `local`)
ReadPreference         readpref.Primary()
Registry               bson.DefaultRegistry
RetryWrites            true
ServerSelectionTimeout 30 * time.Second
Direct                 false
SocketTimeout          nil (infinite)
TLSConfig              nil
WriteConcern           nil (server default `w:1`)
ZlibLevel              6 (if zlib compression enabled)

理论要掌握,实操不能落!以上关于《mongo-go-driver 中的 clientOptions 的默认值是什么?》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>