-
Notifications
You must be signed in to change notification settings - Fork 236
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
Remove port when using mongodb+srv #497
Conversation
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
@jareeve, thanks for the PR. Could you please sign the CLA https://cla.strongloop.com/agreements/strongloop/loopback-connector-mongodb? Thanks. |
lib/mongodb.js
Outdated
@@ -57,6 +57,11 @@ function generateMongoDBURL(options) { | |||
options.port = options.port || 27017; | |||
options.database = options.database || options.db || 'test'; | |||
var username = options.username || options.user; | |||
var portUrl = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing the ending ;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the ; and linter is now passing
Looks like travis is failing with: 1 failing
But I saw this failure before I made any code changes. Is it an already known failure? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jareeve Thank you for your patch! Can you please add some notes in the README for the connector about this change? (something like what you have in the description of the issue related to this PR). Also, please add test(s) to verify that the correct connection url string is built for protocol type.
@dhmlau My fix doesn't seem to be merged into master. If master fails then we should fix it first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jareeve Thank you for the contribution!
Don't worry about the failing test, it shouldn't be related to your PR.
I left a nitpick comment for code refactor. Otherwise your change looks reasonable to me.
And yes please add at least a unit test to verify the generated url is correct. If you can test a 'mongodb+srv' connection works that's even better.
lib/mongodb.js
Outdated
@@ -57,6 +57,11 @@ function generateMongoDBURL(options) { | |||
options.port = options.port || 27017; | |||
options.database = options.database || options.db || 'test'; | |||
var username = options.username || options.user; | |||
var portUrl = ''; | |||
// only include port if not using mongodb+srv | |||
if(options.protocol !== 'mongodb+srv') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: can we use a truthy assertion here?
Like
if(options.protocal === 'mongodb+srv') {
options.port = '';
}
And then you don't have to make the code change on line 74 and 83.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow, I need the change on 74 and 83 to remove the : as well as the port number. Pretty sure the url will not be valid with : in it.
@jannyHou I have added a unit test and added some details to the readme about using mongo+srv. I have posted a comment above about your proposed change as i think it will not work. |
@jannyHou let me know if there is anything else you need me to do on this pr. |
@slnode test please |
CI failed because of the error mentioned above. |
test/mongodb.test.js
Outdated
}; | ||
module.generateMongoDBURL(options).should.be.eql('mongodb://fakeHostname:9999/fakeDatabase'); | ||
}); | ||
it('when protocol is mongodb and no username/password', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name of test should be 'when protocol is mongodb and username/password' since this test
IS passing user name and password in the options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected to state it has username and password
test/mongodb.test.js
Outdated
// mongodb+srv url should not have the port in it | ||
module.generateMongoDBURL(options).should.be.eql('mongodb+srv://fakeHostname/fakeDatabase'); | ||
}); | ||
it('when protocol is mongodb+srv and no username/password', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name of test should be 'when protocol is mongodb+srv and username/password' since the
user name and password IS being passed in the options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected to state it has username and password
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work. :)
Please see my comments about 2 mocha test 'titles' that need to be changed.
@jareeve , thanks for correcting the test case names. Please fix the lint problem with the long commit message This title is too long: |
I think I have fixed everything due to me. |
@slnode test please |
@jareeve, thanks! one last thing, could you please squash your commits? |
@emonddr , could you please help land this PR? Thanks! |
@slnode test please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The windows failure is not related, the vm needs to upgrade mongodb from 3.2 to 3.4 to support new features.
@jareeve thanks for your contribution. Your PR has landed! 🎉 |
Description
When using protocol mongodb+srv the port must not be set in the connection url.
Related issues
#496
Checklist
guide