无法使用 Vert.x MongoClient 连接到 MongoDB Atlas

Unable to connect to MongoDB Atlas using Vert.x MongoClient

我正在尝试使用 Vert.x MongoClient:

连接到托管在 MongoDB Atlas 中的 MongoDB 数据库

我正在使用此代码 (Kotlin) 创建 MongoClient:

MongoClient.create(vertx, jsonObjectOf(
  "connection_string" to "mongodb+srv://<username>:<password>@<cluster_address>/my_db"
))

(显然是真实值)

但是我无法对数据库执行任何操作。我收到连接超时错误:

com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=REPLICA_SET, servers=[{address=<server1_address>, type=UNKNOWN, state=CONNECTING}, {address=<server2_address>, type=UNKNOWN, state=CONNECTING}, {address=<server3_address>, type=UNKNOWN, state=CONNECTING}]

如果我尝试使用 mongosh(CLI 工具)和 MongoDB Compass 使用相同的连接字符串进行连接,它工作正常。

我尝试使用参数(主机、端口等...)而不是使用连接字符串来配置客户端,但在进行查询时出现此错误:

MongoSocketReadException: Prematurely reached end of stream

经过 11 天的努力,我刚刚解决了它。

我在创建 MongoClient 时包含了 "trustAll" : true 选项,现在可以使用了。这不是最好的解决方案,但无论如何...