Skip to content

Commit

Permalink
Incorporate review comments
Browse files Browse the repository at this point in the history
Signed-off-by: jaishirole <jaishirole@gmail.com>
  • Loading branch information
jaishirole committed May 2, 2022
1 parent ab7ac59 commit 5621605
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
6 changes: 6 additions & 0 deletions lib/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,12 @@ function processMongoDBURL(settingsDatabase, mongoUrl) {
baseUrl = 'mongodb://';
else if (mongoUrl.startsWith('mongodb+srv:'))
baseUrl = 'mongodb+srv://';
else if (mongoUrl.startsWith('loopback-connector-mongodb:'))
baseUrl = 'loopback-connector-mongodb://';
else if (mongoUrl.startsWith('loopback-connector-mongodb+srv:'))
baseUrl = 'loopback-connector-mongodb+srv://';
else
return mongoUrl; // Not a MongoURL that we can process

let remainderUrl = mongoUrl.substring(baseUrl.length);
// 2. Check if userId/password is present
Expand Down
45 changes: 36 additions & 9 deletions test/mongodb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1331,9 +1331,12 @@ describe('mongodb connector', function() {
function(err, updatedusers) {
should.exist(err);
err.name.should.equal('MongoError');
err.errmsg.should.equal(
"The dollar ($) prefixed field '$rename' in '$rename' is not allowed in the context of an update's " +
'replacement document. Consider using an aggregation pipeline with $replaceWith.',
err.errmsg.should.equalOneOf(
("The dollar ($) prefixed field '$rename' in '$rename' is not " +
"allowed in the context of an update's replacement document. Consider using an " +
'aggregation pipeline with $replaceWith.'),
('The dollar ($) prefixed ' +
"field '$rename' in '$rename' is not valid for storage."),
);
done();
},
Expand All @@ -1356,9 +1359,12 @@ describe('mongodb connector', function() {
function(err, updatedusers) {
should.exist(err);
err.name.should.equal('MongoError');
err.errmsg.should.equal(
"The dollar ($) prefixed field '$rename' in '$rename' is not allowed in the context of an update's " +
'replacement document. Consider using an aggregation pipeline with $replaceWith.',
err.errmsg.should.equalOneOf(
("The dollar ($) prefixed field '$rename' in '$rename' is not " +
"allowed in the context of an update's replacement document. Consider using an " +
'aggregation pipeline with $replaceWith.'),
('The dollar ($) prefixed ' +
"field '$rename' in '$rename' is not valid for storage."),
);
done();
},
Expand Down Expand Up @@ -1413,9 +1419,12 @@ describe('mongodb connector', function() {
function(err, updatedusers) {
should.exist(err);
err.name.should.equal('MongoError');
err.errmsg.should.equal(
"The dollar ($) prefixed field '$rename' in '$rename' is not allowed in the context of an update's " +
'replacement document. Consider using an aggregation pipeline with $replaceWith.',
err.errmsg.should.equalOneOf(
("The dollar ($) prefixed field '$rename' in '$rename' is not " +
"allowed in the context of an update's replacement document. Consider using an " +
'aggregation pipeline with $replaceWith.'),
('The dollar ($) prefixed ' +
"field '$rename' in '$rename' is not valid for storage."),
);
done();
},
Expand Down Expand Up @@ -3430,6 +3439,24 @@ describe('mongodb connector', function() {
module.processMongoDBURL(database, url).should.be.eql('mongodb://db1.example.com:27017,db2.example.com:32667/mydb?authSource=admin&replicaSet=replset&readPreference=primary&ssl=true');
});

it('when no seetings db, lb4 url has no db, no user credentials, single host, and no options', function() {
const url = 'loopback-connector-mongodb://localhost:27017';
const database = '';
module.processMongoDBURL(database, url).should.be.eql('loopback-connector-mongodb://localhost:27017/');
});

it('when no seetings db, lb4 srv url has no db, no user credentials, single host, and no options', function() {
const url = 'loopback-connector-mongodb+srv://localhost:27017';
const database = '';
module.processMongoDBURL(database, url).should.be.eql('loopback-connector-mongodb+srv://localhost:27017/');
});

it('when it is not mongo url', function() {
const url = 'http://localhost:27017';
const database = '';
module.processMongoDBURL(database, url).should.be.eql('http://localhost:27017');
});

it('when no seetings db, url has no db, no user credentials, single host, and no options', function() {
const url = 'mongodb://localhost:27017';
const database = '';
Expand Down

0 comments on commit 5621605

Please sign in to comment.