Cannot connect to an IPv6-only server via a domain name

We have IPv6-only servers that we connect to via a domain name (not actual domain or address):

host mongo-001.example.com

mongo-001.example.com has IPv6 address 2a02:26f0:a00::5435:ac51
Host mongo-001.example.com not found: 3(NXDOMAIN)

Studio 3T correctly connects and I can browse the collections, see server status, etc. Testing the connection in the connect dialog also shows all OK. Using an IPv6 address directly also works.

However, when using a domain name, as soon as I try to run a query, MongoDB Shell terminates:

db.getCollection("hello.bookings").find({})
Current Mongosh Log ID:	6808b06501c9a5f170b0834a
Using Mongosh:		2.4.2
mongosh 2.5.0 is available for download: https://www.mongodb.com/try/download/shell

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/

>
> Uncaught:

MongoRuntimeError: Unable to parse [mongo-001.example.com]:27017 with URL
Caused by: 

TypeError: Invalid URL
>

This is because Studio 3T passes the URL as [mongo-001.example.com]:27017 and not mongo-001.example.com:27017.

If I do it manually, this works:

~/.3T/third-party/2025.7.0/mongosh/sh-2.4.2$ ./mongosh mongodb://mongo-001.example.com:27017

Current Mongosh Log ID:	6808b10e50ce86e9f0b0834a
Connecting to:		mongodb://mongo-001.example.com:27017/?directConnection=true&appName=mongosh+2.4.2
Using MongoDB:		6.0.8
Using Mongosh:		2.4.2

And this does not:

~/.3T/third-party/2025.7.0/mongosh/sh-2.4.2$ ./mongosh mongodb://[mongo-001.example.com]:27017

Current Mongosh Log ID:	6808b18e94a0a78ddeb1834a
Connecting to:		mongodb://[mongo-001.example.com]:27017/?directConnection=true&appName=mongosh+2.4.2
MongoRuntimeError: Unable to parse [mongo-001.example.com]:27017 with URL

Switching to the legacy shell also does not work, because it needs an --ipv6 flag, which there does not seem to be a way to configure.

This works:

~/.3T/third-party/2025.7.0/shell/5.0.x$ ./mongo --ipv6 mongodb://mongo-001.example.com:27017

MongoDB shell version v5.0.10
connecting to: mongodb://mongo-001.example.com:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("58683cef-6a47-483d-86ab-79eda32d4ec3") }
MongoDB server version: 6.0.8

And this does not:

~/.3T/third-party/2025.7.0/shell/5.0.x$ ./mongo mongodb://mongo-001.example.com:27017

MongoDB shell version v5.0.10
connecting to: mongodb://mongo-001.example.com:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server mongo-001.example.com:27017, connection attempt failed: HostNotFound: Could not find address for mongo-001.example.com:27017: SocketException: Host not found (authoritative) :
connect@src/mongo/shell/mongo.js:372:17
@(connect):2:6
exception: connect failed
exiting with code 1

The problem occurs on both Windows and Linux.