From b20eaf3376afe76760ddb2e2bd320ffa2a9d9a31 Mon Sep 17 00:00:00 2001 From: Bryan Tong Date: Thu, 9 Jan 2014 16:47:33 -0700 Subject: [PATCH] fixed to only search string fields --- README.md | 8 ++++++++ lib/mongoose-list.js | 4 ++-- package.json | 2 +- test/model.js | 15 +++++++++++++++ test/mongoose-list.test.js | 0 5 files changed, 26 insertions(+), 3 deletions(-) mode change 100644 => 100755 README.md mode change 100644 => 100755 lib/mongoose-list.js mode change 100644 => 100755 package.json mode change 100644 => 100755 test/model.js mode change 100644 => 100755 test/mongoose-list.test.js diff --git a/README.md b/README.md old mode 100644 new mode 100755 index a0ae327..2ec91aa --- a/README.md +++ b/README.md @@ -85,3 +85,11 @@ Uses a Mongoose style sort string eg: `+name -author' * Default `''` Filter results by value applying to the `searchFields` + +## Changelog + +### 0.1.1 +* Fixed bug with searching on non string fields + +### 0.1.0 +* Initial Release \ No newline at end of file diff --git a/lib/mongoose-list.js b/lib/mongoose-list.js old mode 100644 new mode 100755 index eac3dcb..0ee43a7 --- a/lib/mongoose-list.js +++ b/lib/mongoose-list.js @@ -20,8 +20,8 @@ module.exports = exports = function list(schema,options){ search.find.$or.push(obj) }) } else { - Model.schema.eachPath(function(path){ - if(0 !== path.indexOf('_')){ + Model.schema.eachPath(function(path,type){ + if(0 !== path.indexOf('_') && String === type.options.type){ var obj = {} obj[path] = searchText search.find.$or.push(obj) diff --git a/package.json b/package.json old mode 100644 new mode 100755 index ea3197a..38469d1 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoose-list", - "version": "0.1.0", + "version": "0.1.1", "description": "List plugin for mongoose that allows pagination, filtering, and sorting.", "homepage": "https://github.com/snailjs/mongoose-list", "bugs": "https://github.com/snailjs/mongoose-list/issues", diff --git a/test/model.js b/test/model.js old mode 100644 new mode 100755 index 50038e0..c752c9d --- a/test/model.js +++ b/test/model.js @@ -7,5 +7,20 @@ exports.model = mongoose.model('Test',new mongoose.Schema({ name: { type: String, require: true + }, + hits: { + type: Number, + require: false, + default: 10 + }, + foo: { + type: mongoose.Schema.Types.Mixed, + require: false, + default: 'fox' + }, + dateCreated: { + type: Date, + require: false, + default: Date.now } })) \ No newline at end of file diff --git a/test/mongoose-list.test.js b/test/mongoose-list.test.js old mode 100644 new mode 100755