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..d34d2b6 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); } }