Skip to content

Commit

Permalink
Refactor collection reference
Browse files Browse the repository at this point in the history
Preferring the more permissive .getCollection(x)  interface over direct member access as it allows databases [beginning with _](https://docs.mongodb.com/manual/reference/method/db.getCollection/#db.getCollection).
  • Loading branch information
tggreene committed Jul 27, 2016
1 parent 20412a1 commit ac64af8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions variety.js
Expand Up @@ -59,7 +59,7 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */
'Please see https://github.com/variety/variety for details.';
}

if (db[collection].count() === 0) {
if (db.getCollection(collection).count() === 0) {
throw 'The collection specified (' + collection + ') in the database specified ('+ db +') does not exist or is empty.\n'+
'Possible collection options for database specified: ' + collNames + '.';
}
Expand All @@ -73,7 +73,7 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */
};
read('collection', null);
read('query', {});
read('limit', db[config.collection].find(config.query).count());
read('limit', db.getCollection(config.collection).find(config.query).count());
read('maxDepth', 99);
read('sort', {_id: -1});
read('outputFormat', 'ascii');
Expand Down Expand Up @@ -311,7 +311,7 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */
return result;
};

var cursor = db[config.collection].find(config.query).sort(config.sort).limit(config.limit);
var cursor = db.getCollection(config.collection).find(config.query).sort(config.sort).limit(config.limit);
var interimResults = cursor.reduce(reduceDocuments, {});
var varietyResults = convertResults(interimResults, cursor.size())
.filter(filter)
Expand All @@ -335,8 +335,8 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */

// replace results collection
log('replacing results collection: '+ resultsCollectionName);
resultsDB[resultsCollectionName].drop();
resultsDB[resultsCollectionName].insert(varietyResults);
resultsDB.getCollection(resultsCollectionName).drop();
resultsDB.getCollection(resultsCollectionName).insert(varietyResults);
}

var createAsciiTable = function(results) {
Expand Down

0 comments on commit ac64af8

Please sign in to comment.