Skip to content

Commit

Permalink
fix collectionNames problem
Browse files Browse the repository at this point in the history
use `collections` to replace `collectionsNames` to fix issue powmedia#19
  • Loading branch information
walkingice committed Mar 31, 2015
1 parent 415c1d8 commit 1bf13e7
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,22 @@ Loader.prototype.clear = function(collectionNames, cb) {
function getCollectionNames(cb) {
//If collectionNames not passed we clear all of them
if (!collectionNames) {
results.db.collectionNames(function(err, names) {
results.db.collections(function(err, items) {
if (err) return cb(err);

//Get the real collection names
names = _.map(names, function(nameObj) {
var fullName = nameObj.name,
parts = fullName.split('.');

//Remove DB name
parts.shift();

//Skip system collections
if (parts[0] == 'system' || parts[0] == 'local') return;

return parts.join('.');
var names = _.map(items, function(item) {
var name = item.s.name;
if (name.indexOf('system.') === 0
|| name.indexOf('local.') === 0) {
//Skip system collections
return;
} else {
return name;
}
});

results.collectionNames = _.compact(names);

cb();
})
} else {
Expand Down Expand Up @@ -505,4 +502,4 @@ var _buildConnectionUri = function(options) {
parts.push(options.db);

return parts.join('');
}
}

0 comments on commit 1bf13e7

Please sign in to comment.