-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative connection string implementation #372
Comments
@vitaly-t Thanks, that is certainly interesting. Does your implementation also support Unix socket paths in place of host/port? |
Oh yes! Here, using a connection string from the spec examples: const cs = require('connection-string');
const a = 'mongodb://user:pass@%2Ftmp%2Fmongodb-27017.sock/authDB?replicaSet=rs';
console.log(cs(a)); Outputs:
My implementation doesn't make it a UNIX-specific or socket-specific case, it treats it as something generic for the host name, always encoding it. |
Example of checking for UNIX socket, based on the supported structure: // cn - your ConnectionString object
const isSocket = cn.hosts && cn.hosts[0].name && cn.hosts[0].name.endsWith('.sock'); |
There have been many updates and improvements to the library. And here's even a nice demo. And it has even better support for Unix sockets now. |
Regarding the connection string spec...
There is now a more generic connection-string, which supports everything the spec needs, and more, in case anybody is interested.
For example, the database name would be
.segments[0]
, if it is specified.The text was updated successfully, but these errors were encountered: