MongoDB 去驱动重置连接

MongoDB Go driver reset connection

我正在使用官方 MongoDB Go 驱动程序 (go.mongodb.org/mongo-driver/mongo)。

作为 ConnectString,我使用 mongodb://localhost:12345/test?maxidletimems=100000000000。 连接代码示例:

clientOptions := options.Client().ApplyURI(ConnectString)

client, err = mongo.Connect(context.Background(), clientOptions)

一段时间后(大约 12 小时)驱动程序重置连接(我认为驱动程序会这样做,因为 mongodb 除了“客户端断开连接”之外不会写入任何日志。

而且我不检查连接(使用 Ping 或其他方式),只是尝试写入。 示例:

coll := client.Database(DatabaseName).Collection(CollectionName)

_, err = coll.InsertOne(context.Background(), item)

这个returns错误"driver: bad connection"

After connection I write some items to db, so collection and other things exists.

I pass maxidletimems ~= 3 years, but connection dies.

发生了什么?如何保持连接?

糟糕,这是来自另一个数据库的消息。命名为Clickhouse。感谢大家