{"id":15643140,"url":"https://github.com/jupe/mongoose-query","last_synced_at":"2025-08-20T23:32:47.130Z","repository":{"id":9808630,"uuid":"11789591","full_name":"jupe/mongoose-query","owner":"jupe","description":"mongoose query creator. Alternative for mongoose-api-query but without schema understanding.","archived":false,"fork":false,"pushed_at":"2024-03-23T19:56:22.000Z","size":415,"stargazers_count":60,"open_issues_count":6,"forks_count":20,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-25T02:02:41.979Z","etag":null,"topics":["javascript","mongoose","mongoose-queries","query-builder"],"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/jupe.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-31T11:40:28.000Z","updated_at":"2024-06-20T21:59:09.703Z","dependencies_parsed_at":"2023-02-17T02:40:36.074Z","dependency_job_id":"d8c61a0d-6b98-4bbb-b139-387160b47e1f","html_url":"https://github.com/jupe/mongoose-query","commit_stats":{"total_commits":143,"total_committers":12,"mean_commits":"11.916666666666666","dds":0.4895104895104895,"last_synced_commit":"f71a8de2ba3e8ca8828bcb79d52a83bcc2e6c96f"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupe%2Fmongoose-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupe%2Fmongoose-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupe%2Fmongoose-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupe%2Fmongoose-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jupe","download_url":"https://codeload.github.com/jupe/mongoose-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230471175,"owners_count":18231193,"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":["javascript","mongoose","mongoose-queries","query-builder"],"created_at":"2024-10-03T11:59:13.502Z","updated_at":"2024-12-19T17:08:34.148Z","avatar_url":"https://github.com/jupe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-query\n[![Build Status](https://travis-ci.org/jupe/mongoose-query.png?branch=master)](https://travis-ci.org/jupe/mongoose-query)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![License badge](https://img.shields.io/badge/license-MIT-blue.svg)](https://img.shields.io)\n[![release](http://github-release-version.herokuapp.com/github/jupe/mongoose-query/release.svg?style=flat)](https://github.com/jupe/mongoose-query/releases/latest)\n[![npm version](https://badge.fury.io/js/mongoose-query.svg)](https://badge.fury.io/js/mongoose-query)\n[![Stars badge](https://img.shields.io/github/stars/jupe/mongoose-query.svg)](https://img.shields.io)\n\nThis library is usefull example with `expressjs` + `mongoose` applications to help construct mongoose query model directly from url parameters. Example:\n\n```\nhttp://localhost/model?q={\"group\":\"users\"}\u0026f=name\u0026sk=1\u0026l=5\u0026p=name\n```\nConverted to:\n```\nmodel.find({group: \"users\"}).select(\"name\").skip(1).limit(5).populate('name')\n```\n\n### Tested with node.js versions\n12.x, 14.x, 16.x,latest release\n\n## Changes log\n\nSee [releases page](https://github.com/jupe/mongoose-query/releases).\n\n## Installation\n\nUse [npm](https://www.npmjs.org/package/mongoose-query):\n```\nnpm install mongoose-query\n```\n\n## Test\n```\nnpm test \u0026\u0026 npm run lint\n```\n\n## Usage Example\n\n```\nvar QueryPlugin = require(mongoose-query);\nvar TestSchema = new mongoose.Schema({});\nTestSchema.plugin(QueryPlugin);\nvar testmodel = mongoose.model('test', TestSchema);\n\n//express route\nmodule.exports = function query(req, res) {\n  testmodel.query(req.query, function(error, data){\n    res.json(error?{error: error}:data);\n  });\n}\n```\n\n## doc\n\n```\nvar QueryPlugin = require(mongoose-query);\nschema.plugin( QueryPlugin(, \u003coptions\u003e) )\n```\noptional `options`:\n* `logger`: custom logger, e.g. winston logger, default: \"dummy logger\"\n* `includeAllParams`: \u003cboolean\u003e Parse also other values. e.g. `?name=me`. default: true\n* `ignoreKeys` : \u003carray{String}\u003e keys to be ignored. Default: []\n\nModel static methods:\n\n`model.query( \u003cquery\u003e(, \u003ccallback\u003e) )`\n\n`model.leanQuery(\u003cquery\u003e(, \u003ccallback\u003e) )`: gives plain objects ([lean](http://mongoosejs.com/docs/api.html#query_Query-lean))\n\n**Note:** without `\u003ccallback\u003e` you get Promise.\n\n**URL API:**\n```\nhttp://www.myserver.com/query?[q=\u003cquery\u003e][\u0026t=\u003ctype\u003e][\u0026f=\u003cfields\u003e][\u0026s=\u003corder\u003e][\u0026sk=\u003cskip\u003e]\n[\u0026l=\u003climit\u003e][\u0026p=\u003cpopulate\u003e][\u0026fl=\u003cboolean\u003e][\u0026map=\u003cmapFunction\u003e][\u0026reduce=\u003creduceFunction\u003e]\n\nq=\u003cquery\u003e                   restrict results by the specified JSON query\n                            regex e.g. q='{\"field\":{\"$regex\":\"/mygrep/\", \"$options\":\"i\"}}'\nt=\u003ctype\u003e                    find|findOne|count|estimateCount|aggregate|distinct|aggregate|mapReduce\nf=\u003cset of fields\u003e           specify the set of fields to include or exclude in each document\n                            (1 - include; 0 - exclude)\ns=\u003csort order\u003e              specify the order in which to sort each specified field\n                            (1- ascending; -1 - descending), JSON\nsk=\u003cnum results to skip\u003e    specify the number of results to skip in the result set;\n                            useful for paging\nl=\u003climit\u003e                   specify the limit for the number of results (default is 1000)\np=\u003cpopulate\u003e                specify the fields for populate, also more complex json object is supported.\nx=\u003cexplain\u003e                 allowed values: 'queryPlanner', 'executionStats', 'allPlansExecution'\nto=\u003cms\u003e                     timeout for query\nd=\u003cboolean\u003e                 allowDiskUse (for heavy queries)\nmap=\u003cmapFunction\u003e           mongodb map function as string\n                            http://docs.mongodb.org/manual/reference/command/mapReduce/#mapreduce-map-cmd'\n                            e.g. \"function(){if (this.status == 'A') emit(this.cust_id, 1);)}\"\nreduce=\u003creduceFunction\u003e     mongodb reduce function as string\n                            http://docs.mongodb.org/manual/reference/command/mapReduce/#mapreduce-reduce-cmd\n                            e.g. \"function(key, values) {return result;}\"\nfl=\u003cboolean\u003e                Flat results or not\n\nSpecial values:\n\"oid:\u003cstring\u003e\"              string is converted to ObjectId\n\"/regex/(options)\"          converted to regex\n{ $regex: /\u003cstring\u003e/,       regex match with optional regex options\n ($options: \"\") }        \n\nAlternative search conditions:\n\"key={i}a\"                  case insensitive\n\"key={e}a\"                  ends with a\n\"key={ei}a\"                 ends with a, case insensitive\n\"key={b}a\"                  begins with a\n\"key={bi}a\"                 begins with a, case insensitive\n\"key={in}a,b\"               At least one of these is in array\n\"key={nin}a,b\"              Any of these values is not in array\n\"key={all}a,b\"              All of these contains in array\n\"key={empty}\"               Field is empty or not exists\n\"key={!empty}\"              Field exists and is not empty\n\"key={mod}a,b\"              Docs where key mod a is b\n\"key={gt}a\"                 value is greater than a\n\"key={gte}a\"                value is greater or equal than a\n\"key={lt}a\"                 value is lower than a\n\"key={lte}a\"                value is lower or equal\n\"key={ne}a\"                 value is not equal\n\"key={size}a\"               value is array, and array size is a\n\"key={sort_by}\"             sort by asc\n\"key={sort_by}-1\"           sort by desc\n\n**References to mongo:**\n- [elemMatch](https://docs.mongodb.com/manual/reference/operator/query/elemMatch/)\n- [size](https://docs.mongodb.com/manual/reference/operator/query/size/)\n```\nResults with `fl=false`:\n```\n[\n {\n \tnest: {\n    ed: {\n      data: 'value',\n      data2':'value'\n    }\n  }\n}\n]\n```\n\nResults with `fl=true`:\n```\n[\n {'nest.ed.data': 'value',\n  'nest.ed.data2':'value'},\n]\n```\n\n\n#### Date\n\nAllowed date formats:\n- `2010/10/1` (y/m/d)\n- `31/2/2010` (d/m/y)\n- `2011-10-10T14:48:00` (ISO 8601)\n\n**Note:**\nOnly valid format is ISO when using date inside `q` -parameter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupe%2Fmongoose-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjupe%2Fmongoose-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupe%2Fmongoose-query/lists"}