diff --git a/README.md b/README.md index 2e1ae8b..e3eb2f3 100755 --- a/README.md +++ b/README.md @@ -88,21 +88,31 @@ Filter results by value applying to the `searchFields` Alternatively, the `find` variable can also be a custom mongoose query object like the following example: - { - find: { - $or: [ - { field1: /something/ }, - { field2: new RegExp('else', 'i') } - ] - } - } +```js +var query = { + find: { + $or: [ + { field1: /something/ }, + { field2: new RegExp('else', 'i') } + ] + } +} +Model.list({start: 0, limit: 10, sort: 'name', find: query},function(err,count,results){ + if(err) throw err + console.log('found ' + count + 'records') + results.forEach(function(row){ + console.log('name: ' + row.name) + }) +}) +``` This allows you to perform custom and complex queries and still make use of the remaining features of this module such as pagination. ## Changelog -### 0.1.2 -* Added custom `find` object support +### 0.2.0 +* Added custom `find` object support that can be a direct mongoose query object rather than having +one built automatically. ### 0.1.1 * Fixed bug with searching on non string fields diff --git a/lib/mongoose-list.js b/lib/mongoose-list.js index e5b6d3f..c9b725c 100755 --- a/lib/mongoose-list.js +++ b/lib/mongoose-list.js @@ -10,7 +10,7 @@ module.exports = exports = function list(schema,options){ search.start = search.start || 0 search.limit = search.limit || 10 search.sort = search.sort || options.sort || '' - if(typeof search.find === 'string'){ + if('string' === typeof search.find){ var searchText = new RegExp(search.find,'i') search.find = {$or: []} if(options.searchFields){ diff --git a/package.json b/package.json index d0d2e6a..83436a1 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoose-list", - "version": "0.1.2", + "version": "0.2.0", "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",