Skip to content
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

Open
vitaly-t opened this issue Jul 13, 2018 · 4 comments
Open

Alternative connection string implementation #372

vitaly-t opened this issue Jul 13, 2018 · 4 comments

Comments

@vitaly-t
Copy link

vitaly-t commented Jul 13, 2018

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.

@p-mongo
Copy link
Contributor

p-mongo commented Aug 13, 2018

@vitaly-t Thanks, that is certainly interesting. Does your implementation also support Unix socket paths in place of host/port?

@p-mongo p-mongo changed the title Alternative implementation Alternative connection string implementation Aug 13, 2018
@vitaly-t
Copy link
Author

vitaly-t commented Aug 14, 2018

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:

ConnectionString {
  protocol: 'mongodb',
  user: 'user',
  password: 'pass',
  hosts: [ { name: '/tmp/mongodb-27017.sock', isIPv6: false } ],
  path: [ 'authDB' ],
  params: { replicaSet: 'rs' } }

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.

@vitaly-t
Copy link
Author

vitaly-t commented Mar 15, 2019

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');

@vitaly-t
Copy link
Author

vitaly-t commented Jul 7, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants