From c1be2912690536b93c9304f2c069da19a4d49962 Mon Sep 17 00:00:00 2001 From: Jimmie Date: Wed, 25 Oct 2017 00:18:33 +0800 Subject: [PATCH 1/3] Add ssl arg and query param to mongo uri. --- bin/mongobq | 2 ++ lib/mongo.js | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/mongobq b/bin/mongobq index 49ba4a5..c17ce6c 100755 --- a/bin/mongobq +++ b/bin/mongobq @@ -13,6 +13,7 @@ program .option('-u, --username ', 'specifies a mongodb username to authenticate') .option('-p, --password ', 'specifies a mongodb password to authenticate') .option('-d, --database ', 'specifies the name of the database') + .option('--ssl', 'specifies to use ssl for mongod connection') .option('-c, --collection ', 'specifies the collection to export') .option('-f, --fields ', 'specifies a field or fields to include in the export') .option('-q, --query ', 'provides a JSON document as a query that optionally limits the documents returned in the export', JSON.parse) @@ -40,6 +41,7 @@ var opts = { collection: program.collection, username: program.username, password: program.password, + ssl: program.ssl, query: program.query || {}, fields: parseFields(program.schema, program.fields), project: program.project, diff --git a/lib/mongo.js b/lib/mongo.js index 7464c66..f7f6863 100644 --- a/lib/mongo.js +++ b/lib/mongo.js @@ -6,10 +6,15 @@ var MongoClient = require('mongodb').MongoClient; var SCHEMA = 'mongodb'; function buildMongodbUri(opts) { + var queryParams = ''; + if opts.ssl { + queryParams += "ssl=true"; + } + if (opts.username) { - return util.format("%s://%s:%s@%s:%d/%s", SCHEMA, opts.username, opts.password, opts.host, opts.port, opts.database); + return util.format("%s://%s:%s@%s:%d/%s?%s", SCHEMA, opts.username, opts.password, opts.host, opts.port, opts.database, queryParams); } else { - return util.format("%s://%s:%d/%s", SCHEMA, opts.host, opts.port, opts.database); + return util.format("%s://%s:%d/%s?%s", SCHEMA, opts.host, opts.port, opts.database, queryParams); } } From 5ecbf9ce1226199458351823c4df5d560734660f Mon Sep 17 00:00:00 2001 From: Jimmie Date: Wed, 25 Oct 2017 00:30:54 +0800 Subject: [PATCH 2/3] Don't add ? to uri if it's not needed. --- lib/mongo.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/mongo.js b/lib/mongo.js index f7f6863..c7ffb90 100644 --- a/lib/mongo.js +++ b/lib/mongo.js @@ -8,13 +8,13 @@ var SCHEMA = 'mongodb'; function buildMongodbUri(opts) { var queryParams = ''; if opts.ssl { - queryParams += "ssl=true"; + queryParams += "?ssl=true"; } if (opts.username) { - return util.format("%s://%s:%s@%s:%d/%s?%s", SCHEMA, opts.username, opts.password, opts.host, opts.port, opts.database, queryParams); + return util.format("%s://%s:%s@%s:%d/%s%s", SCHEMA, opts.username, opts.password, opts.host, opts.port, opts.database, queryParams); } else { - return util.format("%s://%s:%d/%s?%s", SCHEMA, opts.host, opts.port, opts.database, queryParams); + return util.format("%s://%s:%d/%s%s", SCHEMA, opts.host, opts.port, opts.database, queryParams); } } From e5235504a08a5c515247716d04a46f2d70689f3c Mon Sep 17 00:00:00 2001 From: Jimmie Date: Wed, 25 Oct 2017 00:34:24 +0800 Subject: [PATCH 3/3] Correct parenthesis use in if statement. --- lib/mongo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mongo.js b/lib/mongo.js index c7ffb90..d34d2b6 100644 --- a/lib/mongo.js +++ b/lib/mongo.js @@ -7,7 +7,7 @@ var SCHEMA = 'mongodb'; function buildMongodbUri(opts) { var queryParams = ''; - if opts.ssl { + if (opts.ssl) { queryParams += "?ssl=true"; }