From 1bf13e77f587e22aa061edf2405e592f2780f75d Mon Sep 17 00:00:00 2001 From: Julian_Chu Date: Tue, 31 Mar 2015 11:53:57 +0800 Subject: [PATCH] fix collectionNames problem use `collections` to replace `collectionsNames` to fix issue #19 --- src/index.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/index.js b/src/index.js index e2e9a73..e47a4fa 100644 --- a/src/index.js +++ b/src/index.js @@ -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 { @@ -505,4 +502,4 @@ var _buildConnectionUri = function(options) { parts.push(options.db); return parts.join(''); -} \ No newline at end of file +}