Skip to content

Commit 3710b02

Browse files
committed
support all mongo find options, instead of just projection
1 parent 4c3e1e3 commit 3710b02

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Option|Description|Default value
4040
`collection`|Name of the collection with your data|**required**
4141
`url`|URL of the Mongo server to which you're connecting|`mongodb://localhost:27017`
4242
`query`|The query you'd like to run to filter the data returned|`{}` (all records)
43-
`projection`|Lets you specify the fields you'd like to return|`{}` (all fields)
43+
`options`|Lets you specify any of the Mongo driver's [find options](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#find). This is especially useful for specifying a `projection` to limit the number of columns returned, or a `limit`, to limit the number of rows.|`{}`
4444
`outputFilePath`|Path to the file to which you want the results written|`./query_results.csv`
4545
`authDb`|Specify the database against which to authenticate|Defaults to the value supplied for `databaseName`
4646

mongo-csv.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const collection = config.collection;
1212
const outputFilePath = config.outputFilePath || './query_results.csv';
1313

1414
const query = config.query || {};
15-
const projection = config.projection || {};
15+
const options = config.options || {};
1616

1717
const mongoQuery = (query) => {
1818
const dateRegex = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/;
@@ -43,7 +43,7 @@ const mongoQuery = (query) => {
4343
try {
4444
await client.connect();
4545
const db = client.db(databaseName);
46-
const cursor = db.collection(collection).find(mongoQuery(query), { projection });
46+
const cursor = db.collection(collection).find(mongoQuery(query), options);
4747
const documents = [];
4848
while (await cursor.hasNext()) {
4949
const document = await cursor.next();

0 commit comments

Comments
 (0)