I was playing around with the idea of using the URI class to build a MongoDB connection string, so I thought I'd start with seeing if it could parse one. Using the example from https://docs.mongodb.com/manual/reference/connection-string/
(see the ReplicaSet tab), I did this (using ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]):
require "uri"
# This example throws: URI::InvalidURIError, bad URI(is not URI?): ....
begin
u = URI("mongodb://myDBReader:D1fficultP%40ssw0rd@mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?authSource=admin&replicaSet=myRepl")
rescue Exception => e
puts "#{e.class}, #{e.message}"
else
puts u.inspect
end
However, if you drop the :27017 port numbers from all, it will parse. Also, if you limit this to one host with/without a port, it parses just ducky.
I was playing around with the idea of using the URI class to build a MongoDB connection string, so I thought I'd start with seeing if it could parse one. Using the example from https://docs.mongodb.com/manual/reference/connection-string/ (see the ReplicaSet tab), I did this (using ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]):
However, if you drop the :27017 port numbers from all, it will parse. Also, if you limit this to one host with/without a port, it parses just ducky.