mongoose-document-search
v1.0.0
Published
mongoose regexp search plugin with pagination
Downloads
1,009
Readme
mongoose-document-search
Search plugin for mongoose
Use plugin for your schema
schema.plugin(documentSearchPlugin)
Use static
search
method for your modelconst result = Model.search(filter, options);
filter
- just like mongoose filter object like for .find
method
type: object
options
- pagination and search options
type: object
page
type: string|number
default: 1
limit
type: string|number
default: 10
sort
type: string|object
- string
asc
ordesc
is used it will be applied forfields
- object
{ createdAt: 1, name: -1 }
fields
type: string[]
search field in filter
object
result
- search response
type: object
data
type: object[]
meta
type: object
{
totalPages
currentPage
firstPage
lastPage
previousPage
nextPage
hasPreviousPage
hasNextPage
totalDocuments
}
Example
Article.search({ title: 'node' }, { limit: 25, page: 1, fields: ['title'] })