From 0a0a597a8b6a6460c55fdb8d1f9ec11160b466b4 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Wed, 19 Jun 2013 18:34:45 +0200 Subject: [PATCH] Some error handling --- lib/datastore.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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;