From 5621605c0a3a852473b5903f76505b5c98f115bd Mon Sep 17 00:00:00 2001 From: jaishirole Date: Tue, 19 Apr 2022 21:39:58 +0530 Subject: [PATCH] Incorporate review comments Signed-off-by: jaishirole --- lib/mongodb.js | 6 ++++++ test/mongodb.test.js | 45 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/lib/mongodb.js b/lib/mongodb.js index d10a00cd8..7a19eb6c7 100644 --- a/lib/mongodb.js +++ b/lib/mongodb.js @@ -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 diff --git a/test/mongodb.test.js b/test/mongodb.test.js index acdae1274..1a5172627 100644 --- a/test/mongodb.test.js +++ b/test/mongodb.test.js @@ -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(); }, @@ -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(); }, @@ -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(); }, @@ -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 = '';