More robust parsing of mongodb connection string. Use new url parser. #1002
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using a more complex mongo connection string the current mongodb connection template throws and error trying to get the database name.
In my case I am connecting to compose.io using the database string:
mongodb://[username]:[password]@aws-us-east-1-portal.20.dblayer.com:21660,aws-us-east-1-portal.21.dblayer.com:21660/compose?authSource=admin&ssl=true
And my app would fail to start with the following error:
MongoError: database names cannot contain the character '.'
.So I am using the
parseConnectionString
function frommongodb-core
to get the database name instead ofurl.parse
, since that can't handle the mongodb failover syntax. I pass in an empty function as the callback sinceMongoClient.connect()
will already throw an error if the mongo connection string is not formatted correctly.I was also getting a
DeprecationWarning
which was fixed for mongoose here cf613ef, so I applied the same fix to the mongodb template.