Skip to content

Commit

Permalink
cleanups to prepare for 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nullivex committed Jan 21, 2014
1 parent f3e1a1f commit 0aa1086
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoose-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 0aa1086

Please sign in to comment.