Mongo-cxx-driver "connection closed"

I’ve been experimenting with the mongo-cxx-driver recently and wanted to see if I could integrate it with JUCE.
My code works fine in an independent single-file project build with CMake, but when I copy it line for line into the AudioProcessor.cpp (Basic Audio Plugin) constructor, I get the following error:
“Exception: No suitable servers found (serverSelectionTryOnce set): [connection closed calling hello on [URL redacted]: generic server error”

Code:
void connectMongoDB()
{
mongocxx::instance inst{};

    const auto uri = mongocxx::uri{[URL redacted]};

    // set version of client Stable API
    mongocxx::options::client client_options;
    const auto api = mongocxx::options::server_api{mongocxx::options::server_api::version::k_version_1};
    client_options.server_api_opts(api);

    mongocxx::options::tls tls_options;
    tls_options.allow_invalid_certificates(true);  // find permament solution for

    client_options.tls_opts(tls_options);

    // Setup the connection and get a handle on the "MyDB" database.
    mongocxx::client conn{ uri, client_options };
    mongocxx::database db = conn["MyDB"];

    // Ping the database.
    const auto ping_cmd = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("ping", 1));
    db.run_command(ping_cmd.view());

}

The JUCE build errors on the last line.
Are TCP connections blocked in JUCE, or do they require additional configuration?