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

Remove port when using mongodb+srv #497

Merged
merged 1 commit into from
Apr 18, 2019
Merged

Conversation

jareeve
Copy link
Contributor

@jareeve jareeve commented Feb 6, 2019

Description

When using protocol mongodb+srv the port must not be set in the connection url.

Related issues

#496

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

@slnode
Copy link

slnode commented Feb 6, 2019

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@dhmlau
Copy link
Member

dhmlau commented Feb 7, 2019

@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 = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing the ending ;

Copy link
Contributor Author

@jareeve jareeve Feb 7, 2019

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

@jareeve
Copy link
Contributor Author

jareeve commented Feb 7, 2019

Looks like travis is failing with:


1 failing

  1. mongodb connector
    does not execute a nested $where:
    Uncaught AssertionError: expected Error {
    code: 'OPERATOR_NOT_ALLOWED_IN_QUERY',
    statusCode: 400,
    details: Object {
    operators: Array [ '$where' ],
    where: Object {
    content: Object {
    $where: 'function() {return this.content.contains("content")}'
    }
    }
    },
    message: 'Operators "$where" are not allowed in query'
    } to not exist
    at Post.find (test/mongodb.test.js:830:24)
    at /home/travis/build/strongloop/loopback-connector-mongodb/node_modules/loopback-datasource-juggler/lib/dao.js:1525:7
    at process._tickCallback (internal/process/next_tick.js:61:11)

But I saw this failure before I made any code changes. Is it an already known failure?

@dhmlau
Copy link
Member

dhmlau commented Feb 7, 2019

@jannyHou, seems like it might be related to the PR that you've worked on: #484. Could you please help on the test failure? Thanks.

Copy link
Contributor

@b-admike b-admike left a 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.

@jannyHou
Copy link
Contributor

jannyHou commented Feb 8, 2019

@dhmlau My fix doesn't seem to be merged into master. If master fails then we should fix it first.

Copy link
Contributor

@jannyHou jannyHou left a 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') {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@jareeve
Copy link
Contributor Author

jareeve commented Feb 11, 2019

@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.

@jareeve
Copy link
Contributor Author

jareeve commented Feb 20, 2019

@jannyHou let me know if there is anything else you need me to do on this pr.

@dhmlau
Copy link
Member

dhmlau commented Feb 24, 2019

@slnode test please

@dhmlau
Copy link
Member

dhmlau commented Mar 9, 2019

@slnode test please
There's PR merged 12 days ago has most of the CI passed. Want to kick it off again for this PR.

@jannyHou @b-admike , please review again. Thanks

@dhmlau dhmlau requested review from jannyHou and b-admike March 9, 2019 15:11
@dhmlau
Copy link
Member

dhmlau commented Mar 9, 2019

CI failed because of the error mentioned above.

};
module.generateMongoDBURL(options).should.be.eql('mongodb://fakeHostname:9999/fakeDatabase');
});
it('when protocol is mongodb and no username/password', function () {
Copy link
Contributor

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

Copy link
Contributor Author

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

// 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 () {
Copy link
Contributor

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.

Copy link
Contributor Author

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

@emonddr emonddr self-requested a review March 19, 2019 13:54
Copy link
Contributor

@emonddr emonddr left a 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.

@dhmlau
Copy link
Member

dhmlau commented Apr 1, 2019

@jareeve , could you please address the review comment from @emonddr ? Thanks.

@jareeve
Copy link
Contributor Author

jareeve commented Apr 4, 2019

@emonddr @dhmlau sorry for the delay but i missed the original comments. i have now updated the test names.

@emonddr
Copy link
Contributor

emonddr commented Apr 4, 2019

@jareeve , thanks for correcting the test case names.

Please fix the lint problem with the long commit message
Click Details
image
and you will see:
image

This title is too long:

image

@emonddr
Copy link
Contributor

emonddr commented Apr 4, 2019

@jannyHou , it seems npm run test is failing on a test not related to @jareeve's changes. Please see @dhmlau comment above. thx. I have copied it below for convenience.

image

@jareeve
Copy link
Contributor Author

jareeve commented Apr 4, 2019

I think I have fixed everything due to me.

@dhmlau
Copy link
Member

dhmlau commented Apr 4, 2019

@slnode test please

@dhmlau
Copy link
Member

dhmlau commented Apr 4, 2019

@jareeve, thanks! one last thing, could you please squash your commits?
See instructions https://loopback.io/doc/en/lb4/submitting_a_pr.html#10-final-rebase-and-squashing-of-commits. Thanks.

@dhmlau
Copy link
Member

dhmlau commented Apr 4, 2019

@emonddr , could you please help land this PR? Thanks!

@dhmlau
Copy link
Member

dhmlau commented Apr 17, 2019

@jannyHou @emonddr, I've rebased the PR and fixed the commit message linting error. Could you please review again? Thanks.

@dhmlau dhmlau requested a review from emonddr April 17, 2019 01:04
@jannyHou
Copy link
Contributor

@slnode test please

Copy link
Contributor

@jannyHou jannyHou left a 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.

@dhmlau dhmlau merged commit cf10c6b into loopbackio:master Apr 18, 2019
@dhmlau
Copy link
Member

dhmlau commented Apr 18, 2019

@jareeve thanks for your contribution. Your PR has landed! 🎉

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

Successfully merging this pull request may close these issues.

6 participants