Skip to content

Commit 0d8f541

Browse files
committed
Incorporate review comments
Signed-off-by: jaishirole <[email protected]>
1 parent 037a7d6 commit 0d8f541

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

lib/mongodb.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,6 +2138,12 @@ function processMongoDBURL(settingsDatabase, mongoUrl) {
21382138
baseUrl = 'mongodb://';
21392139
else if (mongoUrl.startsWith('mongodb+srv:'))
21402140
baseUrl = 'mongodb+srv://';
2141+
else if (mongoUrl.startsWith('loopback-connector-mongodb:'))
2142+
baseUrl = 'loopback-connector-mongodb://';
2143+
else if (mongoUrl.startsWith('loopback-connector-mongodb+srv:'))
2144+
baseUrl = 'loopback-connector-mongodb+srv://';
2145+
else
2146+
return mongoUrl; // Not a MongoURL that we can process
21412147

21422148
let remainderUrl = mongoUrl.substring(baseUrl.length);
21432149
// 2. Check if userId/password is present

test/mongodb.test.js

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,9 +1331,12 @@ describe('mongodb connector', function() {
13311331
function(err, updatedusers) {
13321332
should.exist(err);
13331333
err.name.should.equal('MongoError');
1334-
err.errmsg.should.equal(
1335-
"The dollar ($) prefixed field '$rename' in '$rename' is not allowed in the context of an update's " +
1336-
'replacement document. Consider using an aggregation pipeline with $replaceWith.',
1334+
err.errmsg.should.equalOneOf(
1335+
("The dollar ($) prefixed field '$rename' in '$rename' is not " +
1336+
"allowed in the context of an update's replacement document. Consider using an " +
1337+
'aggregation pipeline with $replaceWith.'),
1338+
('The dollar ($) prefixed ' +
1339+
"field '$rename' in '$rename' is not valid for storage."),
13371340
);
13381341
done();
13391342
},
@@ -1356,9 +1359,12 @@ describe('mongodb connector', function() {
13561359
function(err, updatedusers) {
13571360
should.exist(err);
13581361
err.name.should.equal('MongoError');
1359-
err.errmsg.should.equal(
1360-
"The dollar ($) prefixed field '$rename' in '$rename' is not allowed in the context of an update's " +
1361-
'replacement document. Consider using an aggregation pipeline with $replaceWith.',
1362+
err.errmsg.should.equalOneOf(
1363+
("The dollar ($) prefixed field '$rename' in '$rename' is not " +
1364+
"allowed in the context of an update's replacement document. Consider using an " +
1365+
'aggregation pipeline with $replaceWith.'),
1366+
('The dollar ($) prefixed ' +
1367+
"field '$rename' in '$rename' is not valid for storage."),
13621368
);
13631369
done();
13641370
},
@@ -1413,9 +1419,12 @@ describe('mongodb connector', function() {
14131419
function(err, updatedusers) {
14141420
should.exist(err);
14151421
err.name.should.equal('MongoError');
1416-
err.errmsg.should.equal(
1417-
"The dollar ($) prefixed field '$rename' in '$rename' is not allowed in the context of an update's " +
1418-
'replacement document. Consider using an aggregation pipeline with $replaceWith.',
1422+
err.errmsg.should.equalOneOf(
1423+
("The dollar ($) prefixed field '$rename' in '$rename' is not " +
1424+
"allowed in the context of an update's replacement document. Consider using an " +
1425+
'aggregation pipeline with $replaceWith.'),
1426+
('The dollar ($) prefixed ' +
1427+
"field '$rename' in '$rename' is not valid for storage."),
14191428
);
14201429
done();
14211430
},
@@ -3430,6 +3439,24 @@ describe('mongodb connector', function() {
34303439
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');
34313440
});
34323441

3442+
it('when no seetings db, lb4 url has no db, no user credentials, single host, and no options', function() {
3443+
const url = 'loopback-connector-mongodb://localhost:27017';
3444+
const database = '';
3445+
module.processMongoDBURL(database, url).should.be.eql('loopback-connector-mongodb://localhost:27017/');
3446+
});
3447+
3448+
it('when no seetings db, lb4 srv url has no db, no user credentials, single host, and no options', function() {
3449+
const url = 'loopback-connector-mongodb+srv://localhost:27017';
3450+
const database = '';
3451+
module.processMongoDBURL(database, url).should.be.eql('loopback-connector-mongodb+srv://localhost:27017/');
3452+
});
3453+
3454+
it('when it is not mongo url', function() {
3455+
const url = 'http://localhost:27017';
3456+
const database = '';
3457+
module.processMongoDBURL(database, url).should.be.eql('http://localhost:27017');
3458+
});
3459+
34333460
it('when no seetings db, url has no db, no user credentials, single host, and no options', function() {
34343461
const url = 'mongodb://localhost:27017';
34353462
const database = '';

0 commit comments

Comments
 (0)