Aggregation from query
Create aggregations to use in mongoose with query params, based in query parser of json-server
Basic usage
const mongoose = ;const processQuery = ; const BookSchema = title: String publishDate: Date price: Number categories: String;const Book = mongoose; ;/*[ { $match: { title: { $regex: "story", $options: "i" } } }, { $match: { publishDate: { $gte: "2020-03-01T00:00:00.000Z" } } }, { $match: { publishDate: { $lte: "2020-07-01T00:00:00.000Z" } } }, { $match: { price: { $lt: 100 } } }, { $sort: { price: 1 } }, { $limit: 10 }, { $project: { title: 1, price: 1 } }];*/
Params support
- Less then
- {attribute}_lt
- Less or equal then
- {attribute}_lte
- Granter then
- {attribute}_gt
- Granter or equal then
- {attribute}_gte
- Equal
- {attribute}_eq
- Not equal
- {attribute}_ne
- Array include
- {attribute}_in
- Array not include
- {attribute}_nin
- Regex
- {attribute}_regex
- Regex with ignore case
- {attribute}_regexi
- Sort by (separeted by comma ',')
- _sort
- _order
- Select (separeted by comma ',') and Non Select (started with '-')
- _select
- Limits and ranges
- _start
- _end
- _page
- _limit
- Full text search (attempt, use with caution)
- q