{"id":23102483,"url":"https://github.com/turistforeningen/node-mongo-querystring","last_synced_at":"2025-04-09T18:18:16.996Z","repository":{"id":57301658,"uuid":"24317175","full_name":"Turistforeningen/node-mongo-querystring","owner":"Turistforeningen","description":"Query builder for accepting URL query parameters into your MongoDB queries. Safe and feature rich. Supports most of MongoDB's query operators such as $eq, $gt, $lt, $ne, $in, $nin, $exists, $regex, geospatial queries such as bbox and near, as well as your own custom query business logic!","archived":false,"fork":false,"pushed_at":"2020-05-01T10:10:09.000Z","size":108,"stargazers_count":101,"open_issues_count":16,"forks_count":31,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-09T18:18:12.354Z","etag":null,"topics":["mongodb","node","nodejs","npm","npm-package","parser","string-parsing","uri-query"],"latest_commit_sha":null,"homepage":"","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/Turistforeningen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-22T06:30:38.000Z","updated_at":"2024-11-30T05:45:09.000Z","dependencies_parsed_at":"2022-08-24T17:10:22.703Z","dependency_job_id":null,"html_url":"https://github.com/Turistforeningen/node-mongo-querystring","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Turistforeningen%2Fnode-mongo-querystring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Turistforeningen%2Fnode-mongo-querystring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Turistforeningen%2Fnode-mongo-querystring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Turistforeningen%2Fnode-mongo-querystring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Turistforeningen","download_url":"https://codeload.github.com/Turistforeningen/node-mongo-querystring/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085326,"owners_count":21045139,"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":["mongodb","node","nodejs","npm","npm-package","parser","string-parsing","uri-query"],"created_at":"2024-12-16T23:59:48.444Z","updated_at":"2025-04-09T18:18:16.972Z","avatar_url":"https://github.com/Turistforeningen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MongoDB QueryString Parser\n\n[![Build status](https://app.wercker.com/status/b33b844c0ab10d56c318e116e587e2fa/s \"wercker status\")](https://app.wercker.com/project/bykey/b33b844c0ab10d56c318e116e587e2fa)\n[![Codacy grade](https://img.shields.io/codacy/grade/782d0dc482ea4033892f99f968090b35.svg \"Codacy grade\")](https://www.codacy.com/app/DNT/node-mongo-querystring)\n[![Codacy coverage](https://img.shields.io/codacy/coverage/782d0dc482ea4033892f99f968090b35.svg \"Codacy coverage\")](https://www.codacy.com/app/DNT/node-mongo-querystring)\n[![NPM downloads](https://img.shields.io/npm/dm/mongo-querystring.svg \"NPM downloads\")](https://www.npmjs.com/package/mongo-querystring)\n[![NPM version](https://img.shields.io/npm/v/mongo-querystring.svg \"NPM version\")](https://www.npmjs.com/package/mongo-querystring)\n[![Node version](https://img.shields.io/node/v/mongo-querystring.svg \"Node version\")](https://www.npmjs.com/package/mongo-querystring)\n[![Dependency status](https://img.shields.io/david/Turistforeningen/node-mongo-querystring.svg \"Dependency status\")](https://david-dm.org/Turistforeningen/node-mongo-querystring)\n\nAccept MongoDB query parameters through URI queries safe and easy. This is\nuseful when building an API and accepting various user specificed queries.\n\n## Features\n\n* Aliased query parameters\n* Blacklisted query parameters\n* Whitelisted query parameters\n* Basic operators\n  * `$eq`\n  * `$gt`\n  * `$gte`\n  * `$lt`\n  * `$lte`\n  * `$ne`\n  * `$in`\n  * `$nin`\n  * `$exists`\n  * `$regex`\n* Parse string integers and floats to numbers\n* Parse string boolean to ture/false booleans\n\n| operation | query string  | query object |\n|-----------|---------------|--------------|\n| equal     | `?foo=bar`    | `{ foo: \"bar\" }` |\n| unequal   | `?foo=!bar`   | `{ foo: { $ne: \"bar\" }}` |\n| exists    | `?foo=`       | `{ foo: { $exists: true }}` |\n| not exists | `?foo=!`     | `{ foo: { $exists: false }}` |\n| greater than | `?foo=\u003e10` | `{ foo: { $gt: 10 }}` |\n| less than | `?foo=\u003c10`    | `{ foo: { $lt: 10 }}` |\n| greater than or equal to | `?foo=\u003e=10` | `{ foo: { $gte: 10 }}` |\n| less than or equal to | `?foo=\u003c=10`    | `{ foo: { $lte: 10 }}` |\n| starts with | `?foo=^bar` | `{ foo: { $regex: \"^bar\", $options: \"i\" }}` |\n| ends with | `?foo=$bar`   | `{ foo: { $regex: \"bar$\", $options: \"i\" }}` |\n| contains  | `?foo=~bar`   | `{ foo: { $regex: \"bar\", $options: \"i\" }}` |\n| in array  | `?foo[]=bar\u0026foo[]=baz` | `{ foo: { $in: ['bar', 'baz'] }}` |\n| not in array | `?foo[]=!bar\u0026foo[]=!baz` | `{ foo: { $nin: ['bar', 'baz'] }}` |\n\n* Geospatial operators\n  * `$geoWithin` (polygon)\n  * `$near` (point)\n\n| operation | query string  | query object |\n|-----------|---------------|--------------|\n| bbox | `?bbox=0,1,2,3` | `{ geojson: { $geoWithin: { $geometry: { … } } } }` |\n| near | `?near=0,1` | `{ geojson: { $near: { $geometry: { … } } } }` |\n| near (max distance) | `?near=0,1,2` | `{ geojson: { $near: { …, $maxDistance: 2 } } }` |\n| near (max \u0026 min distance) | `?near=0,1,2,3` | `{ geojson: { $near: { …, $minDistance: 3 } } }` |\n\n* Custom query functions\n  * `after` (date)\n  * `before` (date)\n  * `between` (date|date)\n\n| operation | query string  | query object |\n|-----------|---------------|--------------|\n| after | `?after=2014-01-01` | `{ endret: { $gte: \"2014-01-01T00:00:00.000Z\" } }` |\n| after | `?after=1388534400` | `{ endret: { $gte: \"2014-01-01T00:00:00.000Z\" } }` |\n| before | `?before=2014-01-01` | `{ endret: { $lt: \"2014-01-01T00:00:00.000Z\" } }` |\n| before | `?before=1388534400` | `{ endret: { $lt: \"2014-01-01T00:00:00.000Z\" } }` |\n| between | `?between=2014-01-01\\|2015-01-01` | `{ endret: { $gte: \"2014-01-01T00:00:00.000Z\", $lt: \"2015-01-01T00:00:00.000Z\" } }` |\n| between | `?between=1388534400\\|1420088400` | `{ endret: { $gte: \"2014-01-01T00:00:00.000Z\", $lt: \"2015-01-01T00:00:00.000Z\" } }` |\n\n## Install\n\n```\nnpm install mongo-querystring --save\n```\n\n## API\n\n```javascript\nvar MongoQS = require('mongo-querystring');\n```\n\n### new MongoQS(`object` options)\n\n* `Array` ops - list of supported operators (default: `['!', '^', '$', '~', '\u003e', '\u003c', '$in']`)\n* `object` alias - query param aliases (default: `{}`)\n* `object` blacklist - blacklisted query params (default: `{}`)\n* `object` whitelist - whitelisted query params (default: `{}`)\n* `object` custom - custom query params (default: `{}`)\n* `object` string - string parsing\n  * `boolean` toBoolean - parse `\"true\"`, `\"false\"` string to booleans (default: `true`)\n  * `boolean` toNumber - parse string integer and float values to numbers (default: `true`)\n* `regexp` keyRegex - allowed key names (default: `/^[a-zæøå0-9-_.]+$/i`)\n* `regexp` arrRegex - allowed array key names (default: `/^[a-zæøå0-9-_.]+(\\[\\])?$/i`)\n\n#### Bult in custom queries\n\n* `bbox` - bounding box geostatial query\n* `near` - proximity geostatial query\n* `after` - modified since query\n\n```javascript\nvar qs = new MongoQS({\n  custom: {\n    bbox: 'geojson',        // your geometry field\n    near: 'geojson',        // your geometry field\n    after: 'updated_on'     // your last modified field\n  }\n});\n```\n\n#### Define custom queries\n\nCustom queries are on the folling form; you define the URL query parameter name\nthat your users will be using and a function which takes the result query object\nand the value for query parameter.\n\n```javascript\nvar qs = new MongoQS({\n  custom: {\n    urlQueryParamName: function(query, input) {\n      // do some processing of input value\n      // add your queries to the query object\n      query['someField'] = input;\n      query['someOtherFiled'] = 'some value';\n    }\n  }\n});\n```\n\n### qs.parse(`object` params)\n\nParams is an object with URI query params and their values. Ex. `req.params`\nif you are working with ExpressJS.\n\n```javascript\nvar query = qs.parse(req.params);\n\nmongo.collection('mycol').find(query, field).toArray(function(err, documents) {\n  // matching documents\n});\n```\n\n### Collaborators\n\nIndividuals making significant and valuable contributions are made Collaborators\nand given commit-access to the project. These individuals are identified by the\nexisting Collaborators and their addition as Collaborators is discussed as a\npull request to this project's README.md.\n\nNote: If you make a significant contribution and are not considered for\ncommit-access log an issue or contact one of the Collaborators directly.\n\n* Andy Klimczak - @andyklimczak\n* Hans Kristian Flaatten - @Starefossen\n* Edward Knowles - @eknowles\n\n## [MIT Licensed](https://raw.githubusercontent.com/Turistforeningen/node-mongo-querystring/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturistforeningen%2Fnode-mongo-querystring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fturistforeningen%2Fnode-mongo-querystring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturistforeningen%2Fnode-mongo-querystring/lists"}