Commit ac64af87 by Tim Greene

Refactor collection reference

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).
parent 20412a16
...@@ -59,7 +59,7 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */ ...@@ -59,7 +59,7 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */
'Please see https://github.com/variety/variety for details.'; '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'+ throw 'The collection specified (' + collection + ') in the database specified ('+ db +') does not exist or is empty.\n'+
'Possible collection options for database specified: ' + collNames + '.'; 'Possible collection options for database specified: ' + collNames + '.';
} }
...@@ -73,7 +73,7 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */ ...@@ -73,7 +73,7 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */
}; };
read('collection', null); read('collection', null);
read('query', {}); 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('maxDepth', 99);
read('sort', {_id: -1}); read('sort', {_id: -1});
read('outputFormat', 'ascii'); read('outputFormat', 'ascii');
...@@ -311,7 +311,7 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */ ...@@ -311,7 +311,7 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */
return result; 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 interimResults = cursor.reduce(reduceDocuments, {});
var varietyResults = convertResults(interimResults, cursor.size()) var varietyResults = convertResults(interimResults, cursor.size())
.filter(filter) .filter(filter)
...@@ -335,8 +335,8 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */ ...@@ -335,8 +335,8 @@ Released by Maypop Inc, © 2012-2016, under the MIT License. */
// replace results collection // replace results collection
log('replacing results collection: '+ resultsCollectionName); log('replacing results collection: '+ resultsCollectionName);
resultsDB[resultsCollectionName].drop(); resultsDB.getCollection(resultsCollectionName).drop();
resultsDB[resultsCollectionName].insert(varietyResults); resultsDB.getCollection(resultsCollectionName).insert(varietyResults);
} }
var createAsciiTable = function(results) { var createAsciiTable = function(results) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment