{"id":16223670,"url":"https://github.com/lykmapipo/express-mquery","last_synced_at":"2025-04-07T07:05:33.351Z","repository":{"id":1875239,"uuid":"44949195","full_name":"lykmapipo/express-mquery","owner":"lykmapipo","description":"Expose mongoose query API through HTTP request.","archived":false,"fork":false,"pushed_at":"2024-12-06T03:54:21.000Z","size":1149,"stargazers_count":41,"open_issues_count":12,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T06:03:17.823Z","etag":null,"topics":["express-mquery","expressjs","filter","filters","http","include","json-api","limit","mongodb","mongoose","operators","pagination","params","query","sort"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lykmapipo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-26T06:03:23.000Z","updated_at":"2025-01-20T20:49:43.000Z","dependencies_parsed_at":"2025-01-03T04:12:04.051Z","dependency_job_id":"71b5b1c4-a5d5-4ed6-8977-16b79440a0e8","html_url":"https://github.com/lykmapipo/express-mquery","commit_stats":{"total_commits":205,"total_committers":4,"mean_commits":51.25,"dds":"0.13658536585365855","last_synced_commit":"9810cb739055284475c37e8858cb7cee234634f5"},"previous_names":[],"tags_count":56,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fexpress-mquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fexpress-mquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fexpress-mquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fexpress-mquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lykmapipo","download_url":"https://codeload.github.com/lykmapipo/express-mquery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608150,"owners_count":20965952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express-mquery","expressjs","filter","filters","http","include","json-api","limit","mongodb","mongoose","operators","pagination","params","query","sort"],"created_at":"2024-10-10T12:19:41.912Z","updated_at":"2025-04-07T07:05:33.317Z","avatar_url":"https://github.com/lykmapipo.png","language":"JavaScript","readme":"express-mquery\n====================\n\n[![Build Status](https://app.travis-ci.com/lykmapipo/express-mquery.svg?branch=master)](https://app.travis-ci.com/lykmapipo/express-mquery)\n[![Dependencies Status](https://david-dm.org/lykmapipo/express-mquery.svg)](https://david-dm.org/lykmapipo/express-mquery)\n[![Coverage Status](https://coveralls.io/repos/github/lykmapipo/express-mquery/badge.svg?branch=master)](https://coveralls.io/github/lykmapipo/express-mquery?branch=master)\n[![GitHub License](https://img.shields.io/github/license/lykmapipo/express-mquery)](https://github.com/lykmapipo/express-mquery/blob/master/LICENSE)\n\n[![Commitizen Friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![Code Style](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)\n[![npm version](https://img.shields.io/npm/v/express-mquery)](https://www.npmjs.com/package/express-mquery)\n\nExpose [mongoose](https://github.com/Automattic/mongoose) query API through HTTP request with partial support of [json-api](http://jsonapi.org/): \n - [sparse-fieldsets](http://jsonapi.org/format/#fetching-sparse-fieldsets)\n - [sorting](http://jsonapi.org/format/#fetching-sorting)\n - [pagination](http://jsonapi.org/format/#fetching-pagination)\n - [filtering](http://jsonapi.org/format/#fetching-filtering)\n - [includes](http://jsonapi.org/format/#fetching-includes)\n\n*Note: Checkout the current [specification](https://github.com/lykmapipo/express-mquery/blob/master/SPECIFICATION.md) for more information.*\n\n## Installation\n```js\n$ npm install --save express-mquery\n```\n\n## Usage\n```js\nimport expess from 'express';\nimport mquery from 'express-mquery';\n\nconst app = express();\napp.use(mquery({ limit: 10, maxLimit: 50 }));\n\n...\n\napp.get('/users', (request, response, next) =\u003e {\n  \n  // obtain request.mquery\n  console.log(request.mquery);\n\n});\n```\n\n## Structure\nOnce parse, `express-mquery` will extend `http request` with `mquery` field\n\nExample:\n\n```js\nGET /invoices?fields=number,amount\u0026filter[name]=Bob\n\u0026filter[amount][$gte]=1200\u0026include=customer,items\n\u0026fields[customer]=name,number\u0026fields[items]=name,price\n\u0026page[number]=1\u0026page[size]=10\u0026sort[number]=1\u0026sort[amount]=-1\n```\n\nWill be parsed into:\n```js\n{\n  filter: { name: \"Bob\", amount: { $gte: 1200 } },\n  paginate: { limit: 10, skip: 0, page: 1 },\n  populate: [\n  \t{ path: \"customer\", select: { name: 1, number: 1 } },\n  \t{ path: \"items\", select: { name: 1, price: 1 } }\n  ],\n  select: { number: 1, amount: 1 },\n  sort: { number: 1, amount: -1 }\n}\n```\n\nWhere:\n- `filter` : Is valid `mongoose` criteria and can be passed to `find()`\n- `paginate` : Contains paging details that can be passed to `limit()`, `skip()`\n- `populate` : Is valid `mongoose` populate option and can be passed to `populate()`\n- `select` : Is valid `mongoose` project options and can be passed to `select()`\n- `sort` : Is valid `mongoose` sort options and can be passed to `sort()`\n\n\n## Querying\n\n\u003eWhen passing values as objects or arrays in URLs, they must be valid JSON\n\n### Sort\n```js\nGET /customers?sort=name\nGET /customers?sort=-name\nGET /customers?sort={\"name\":1}\nGET /customers?sort={\"name\":1, \"email\":-1}\n\nor\n\nGET /customers?sort=name\nGET /customers?sort=-name\nGET /customers?sort[name]=1\u0026sort[email]=-1\n```\n\n### Page\n```js\nGET /customers?page=1\nGET /customers?page=1\u0026limit=10\nGET /customers?page[number]=1\u0026page[size]=10\n```\n\n### Skip\n```js\nGET /customers?skip=10\n```\n\n### Limit\nOnly overrides `maximum limit option set by the plugin` if the queried limit is lower\n```js\nGET /customers?limit=10\n```\n\n### Query or Filters\nSupports all [mongodb operators](https://docs.mongodb.com/manual/reference/operator/query/) `($regex, $gt, $gte, $lt, $lte, $ne, etc.)`\n\n```js\nGET /customers?query={\"name\":\"Bob\"}\nGET /customers?query={\"name\":{\"$regex\":\"/Bo$/\"}}\nGET /customers?query={\"age\":{\"$gt\":12}}\nGET /customers?query={\"age\":{\"$gte\":12}}\n\nor\n\nGET /customers?filter[name]=Bob\nGET /customers?filter[name][$regex]=\"/Bo$/\"\nGET /customers?filter[age][$gt]=12\nGET /customers?filter[age][$gte]=12\n```\n\n### Populate or Include\nWorks with create, read and update operations\n\n```js\nGET /invoices?populate=customer\nGET /invoices?populate={\"path\":\"customer\"}\nGET /invoices?populate=[{\"path\":\"customer\"},{\"path\":\"products\"}]\n\nor\n\nGET /invoices?include=customer\nGET /invoices?include[customer]=name,number\u0026includes[items]=name,price\nGET /invoices?include=customer,items\u0026fields[customer]=name,number\u0026fields[items]=name,price\n```\n\n### Select or Fields\n`_id` is always returned unless explicitely excluded\n\n```js\nGET /customers?select=name\nGET /customers?select=-name\nGET /customers?select={\"name\":1}\nGET /customers?select={\"name\":0}\n\nor\n\nGET /customers?fields=name\nGET /customers?fields=-name\nGET /customers?fields=name,email\nGET /invoices?include=customer\u0026fields[customer]=name\n```\n\n## Testing\n\n* Clone this repository\n\n* Install `grunt-cli` global\n\n```sh\n$ npm install -g grunt-cli\n```\n\n* Install all development dependencies\n\n```sh\n$ npm install\n```\n\n* Then run test\n\n```sh\n$ npm test\n```\n\n## Contribute\n\nFork this repo and push in your ideas. Do not forget to add a bit of test(s) of what value you adding.\n\n## Licence\n\nCopyright (c) lykmapipo \u0026 Contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykmapipo%2Fexpress-mquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flykmapipo%2Fexpress-mquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykmapipo%2Fexpress-mquery/lists"}