From e0262af351412dfabea992bfce5410cb4f519d30 Mon Sep 17 00:00:00 2001 From: Jimmie Date: Wed, 25 Oct 2017 00:25:04 +0800 Subject: [PATCH] Pass in fields as json instead of comma delimited list. --- bin/mongobq | 4 ++-- lib/mongo.js | 2 +- lib/mongobq.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/mongobq b/bin/mongobq index 49ba4a5..18d7506 100755 --- a/bin/mongobq +++ b/bin/mongobq @@ -14,7 +14,7 @@ program .option('-p, --password ', 'specifies a mongodb password to authenticate') .option('-d, --database ', 'specifies the name of the database') .option('-c, --collection ', 'specifies the collection to export') - .option('-f, --fields ', 'specifies a field or fields to include in the export') + .option('-f, --fields ', 'specifies a field or fields to include in the export', JSON.parse) .option('-q, --query ', 'provides a JSON document as a query that optionally limits the documents returned in the export', JSON.parse) .option('-K, --keyfile ', 'specifies the key file path') .option('-B, --bucket ', 'specifies the Google Cloud Storage bucket name') @@ -41,7 +41,7 @@ var opts = { username: program.username, password: program.password, query: program.query || {}, - fields: parseFields(program.schema, program.fields), + fields: program.fields, project: program.project, keyfile: program.keyfile, bucket: program.bucket, diff --git a/lib/mongo.js b/lib/mongo.js index 7464c66..39b9b61 100644 --- a/lib/mongo.js +++ b/lib/mongo.js @@ -30,7 +30,7 @@ function Mongo(opts) { this.mongodbUri = buildMongodbUri(opts); this.collection = opts.collection; this.query = opts.query || {}; - this.fields = buildField(opts.fields); + this.fields = opts.fields; this.limit = opts.limit; this.skip = opts.skip; this.db = null; diff --git a/lib/mongobq.js b/lib/mongobq.js index 03e4961..1580e24 100644 --- a/lib/mongobq.js +++ b/lib/mongobq.js @@ -99,7 +99,7 @@ MongoBQ.prototype.uploadToGCS = function (next) { var count = 0; var autoSchemaDetection = !self.opts.schema; var schema = self.opts.schema || []; - var fields = self.opts.fields || []; + var fields = self.opts.fields; var stream = self.mongo.stream(self.opts.batchSize) .pipe(GCP.BigQueryTable.createJSONStream(schema, autoSchemaDetection)) .on('data', function (d) { count++; })