{"id":15190642,"url":"https://github.com/bluehalo/mongoose-query-service","last_synced_at":"2026-05-07T08:33:30.503Z","repository":{"id":18556817,"uuid":"84591180","full_name":"bluehalo/mongoose-query-service","owner":"bluehalo","description":"NPM module to provide shareable services and plugins for Mongoose models","archived":false,"fork":false,"pushed_at":"2022-06-16T12:34:12.000Z","size":124,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-09-14T14:54:55.070Z","etag":null,"topics":["mongoose","mongoosejs","npm","npm-module","npm-package"],"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/bluehalo.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":"2017-03-10T18:53:24.000Z","updated_at":"2022-06-15T14:29:35.000Z","dependencies_parsed_at":"2022-09-16T00:10:17.439Z","dependency_job_id":null,"html_url":"https://github.com/bluehalo/mongoose-query-service","commit_stats":null,"previous_names":["asymmetrik/mongoose-query-service"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/bluehalo/mongoose-query-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluehalo%2Fmongoose-query-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluehalo%2Fmongoose-query-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluehalo%2Fmongoose-query-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluehalo%2Fmongoose-query-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bluehalo","download_url":"https://codeload.github.com/bluehalo/mongoose-query-service/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluehalo%2Fmongoose-query-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30101761,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T23:59:36.199Z","status":"ssl_error","status_checked_at":"2026-03-04T23:56:48.556Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["mongoose","mongoosejs","npm","npm-module","npm-package"],"created_at":"2024-09-27T20:43:17.216Z","updated_at":"2026-03-05T00:04:16.028Z","avatar_url":"https://github.com/bluehalo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @asymmetrik/mongoose-query-service\n\n[![Build Status](https://travis-ci.org/Asymmetrik/mongoose-query-service.svg)](https://travis-ci.org/Asymmetrik/mongoose-query-service)\n[![Code Climate](https://codeclimate.com/github/Asymmetrik/mongoose-query-service/badges/gpa.svg)](https://codeclimate.com/github/Asymmetrik/mongoose-query-service)\n[![Test Coverage](https://codeclimate.com/github/Asymmetrik/mongoose-query-service/badges/coverage.svg)](https://codeclimate.com/github/Asymmetrik/mongoose-query-service/coverage)\n[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)\n\n\u003e NPM module to provide common services and plugins for Mongoose models\n\n## Table of Contents\n\n- [Use](#use)\n- [Install](#install)\n- [Usage](#usage)\n- [API](#api)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Use\n`@asymmetrik/mongoose-query-service` provides utility services for creating and executing Mongoose queries based on a simple input search object. Additionally, it provides several plugins (`pageable` and `gettable`) that can be applied to Mongoose Schemas to allow them to add functionality to those Mongoose Schemas.\n\n## Install\n\nInclude this module as a dependency of your application in the `package.json` file. For example:\n```\n{\n  ...\n  dependencies: {\n    \"@asymmetrik/mongoose-query-service\": \"latest\"\n  }\n  ...\n}\n```\n\n## Usage\n\nInclude the module via `require` wherever applicable:\n```\nvar mongooseQueryService = require('@asymmetrik/mongoose-query-service');\n```\n\n### Plugins\n\nApply any of the plugins to a Mongoose model using the `.plugin(...)` method provided by Mongoose. For example:\n```\nvar Person = new Schema({});\nPerson.plugin(mongooseQueryService.plugins.pageable);\n```\n\n### Services\n\nService methods are available from the base `@asymmetrik/mongoose-query-service` module, and can be called directly with the parameters defined in the API below.\n\n## API\n\n### Plugins\n\nThe following plugins are available at the top level `plugins` attribute:\n\n#### pageable\n\nApplying the `pageable` plugin at `mongooseQueryService.plugins.pageable` adds a static method to Mongoose model called `pagingSearch` that takes an input object parameter with the following attributes:\n\nAttribute | Optional? | Default | Description\n------------ | ------------- | ------------ | -------------\nquery | Yes | `{}` | Filters to pass to the Mongo query\nprojection | Yes | `{}` | Attributes to return in the elements\noptions | Yes | `{}` | Query options specified by Mongoose\nsearchTerms | Yes | null | String of search terms that will be translated into a search on the text index for the model\npopulate | Yes | null | Populate options specified by Mongoose\nsorting | Yes | {} | Attributes for sorting and directions of each sort. Defaults to descending sort. Accepts either an object with a standard Mongo sorting config or an array of objects with `property` and `direction` attributes that will be translated into the standard Mongo sorting config.\npage | Yes | 0 | To support paged searches, combines with `limit` to set the `skip` attribute of the Mongo query. If `limit` is not provided, `page` is not used.\nlimit | Yes | null | If provided, returns up to this number of results. Combines with the `page` parameter when setting the `skip` attribute of the Mongo query\n\nThe `pagingSearch` method returns a Promise resolved with an object with the following attributes:\n\nAttribute | Type | Description\n------------ | ------------- | ------------\nhasMore | Boolean | Indicates if more documents are available if the next page of results is queried\ntotalSize | Number | The total count of documents that passed the query filter\npageNumber | Number | The current page of results returned. `0` if not paging\npageSize | Number | The current size of each page returned. Set to the input `limit` value (if provided) or the actual size\ntotalPages | Number | The number of pages from the the total size and page size configuration\nelements | Array | The results that were found matching the current page.\n\n*Example:*\n```\nvar Person = new Schema({});\nPerson.plugin(mongooseQuerySchema.plugins.pageable);\n```\n\n#### gettable\n\nApplying the `gettable` plugin at `mongooseQueryService.plugins.gettable` sets the `toObject` and `toJSON` attributes of the Mongoose Schema to `{ getters: true }` so that any `get` method defined in a Schema Type is used when the `toObject` or `toJSON` methods are invoked on the Mongoose model.\n\n*Example:*\n```\nvar Person = new Schema({});\nPerson.plugin(mongooseQuerySchema.plugins.gettable);\n```\n\n### Services\n\n#### buildQuery(query, pagingParameters)\n\nConverts input query and paging parameters into a pageable query object to be used with the `pageable` plugin's `pagingSearch` function.\n\nReturns a promise resolved with the resulting search config object with the attributes:\n\nAttribute | Type | Description\n------------ | ------------- | ------------\nquery | Boolean | Indicates if more documents are available if the next page of results is queried\nsorting | Object | If a `sort` attribute of `pagingParameters` is set, builds a sorting object with a direction set by the `dir` attribute (defaulting to -1 for descending, or set by 'DESC' or 'ASC').\npage | Number | Set by the input `page` attribute of `pagingParameters` passed into the `getPage` method\nlimit | Number | Set by the input `size` attribute of `pagingParameters` passed into the `getLimit` method\n\n#### validateNonEmpty\nReturns true of the input value is not empty (using the lodash *isEmpty* function)\n\n#### parseDate\nParse an input as a date. Handles various types of inputs, such as Strings, Date objects, and Numbers.\n\n@param {date} The input representing a date / timestamp\n\n@returns The timestamp in milliseconds since the Unix epoch\n\n#### getLimit\nGet the limit provided by the input query parameters, if there is one. Limit is taken from the `size` attribute of the input `queryParams` object. Limit has to be at least 1 with a default value of 20 and no more than the max value.\n\n@param queryParams\n\n@param maxSize (optional) default: 100\n\n@returns {number}\n\n#### getPage\nPage needs to be positive and has no upper bound. Taken from the `page` attribute of the input `queryParams` object. Defaults to 0.\n\n@param queryParams\n\n@returns {number}\n\n#### contains\nDetermine if an array contains a given element by doing a deep comparison.\n\n@param arr\n\n@param element\n\n@returns {boolean} True if the array contains the given element, false otherwise.\n\n#### toMongoose\nConverts an input Mongo query, possibly with $date and $obj attributes, to a query that Mongoose supports with Date and ObjectId objects mapped from those inputs as appropriate.\n\n@param obj\n\n@returns {object}\n\n## Contribute\n\nPRs accepted.\n\n\n## License\n\nSee LICENSE for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluehalo%2Fmongoose-query-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluehalo%2Fmongoose-query-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluehalo%2Fmongoose-query-service/lists"}