diff --git a/lib/datastore.js b/lib/datastore.js index 6ee40e5..2278133 100644 --- a/lib/datastore.js +++ b/lib/datastore.js @@ -186,8 +186,6 @@ Datastore.prototype.getCandidates = function (query) { var indexNames = Object.keys(this.indexes) , usableQueryKeys; - if (indexNames.length <= 1) { return this.getAllData(); } // No index defined (except _id), no specific candidate - // For a basic match usableQueryKeys = []; Object.keys(query).forEach(function (k) { @@ -203,7 +201,7 @@ Datastore.prototype.getCandidates = function (query) { // For a $in match usableQueryKeys = []; Object.keys(query).forEach(function (k) { - if (query[k].hasOwnProperty('$in')) { + if (query[k] && query[k].hasOwnProperty('$in')) { usableQueryKeys.push(k); } }); @@ -215,7 +213,7 @@ Datastore.prototype.getCandidates = function (query) { // For a comparison match usableQueryKeys = []; Object.keys(query).forEach(function (k) { - if (query[k].hasOwnProperty('$lt') || query[k].hasOwnProperty('$lte') || query[k].hasOwnProperty('$gt') || query[k].hasOwnProperty('$gte')) { + if (query[k] && (query[k].hasOwnProperty('$lt') || query[k].hasOwnProperty('$lte') || query[k].hasOwnProperty('$gt') || query[k].hasOwnProperty('$gte'))) { usableQueryKeys.push(k); } }); @@ -225,7 +223,7 @@ Datastore.prototype.getCandidates = function (query) { } // By default, return all the DB data - return this.getAllData(); + return this.getAllData(); }; @@ -583,4 +581,5 @@ Datastore.prototype.remove = function () { + module.exports = Datastore;