{"id":15917630,"url":"https://github.com/dsfields/ordery-mongodb-node","last_synced_at":"2025-04-03T11:42:03.815Z","repository":{"id":57316166,"uuid":"122530004","full_name":"dsfields/ordery-mongodb-node","owner":"dsfields","description":"Convert Ordery expressions into MongoDB sort documents.","archived":false,"fork":false,"pushed_at":"2018-02-25T16:25:35.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T10:55:48.356Z","etag":null,"topics":[],"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/dsfields.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-22T20:13:49.000Z","updated_at":"2018-02-25T16:19:59.000Z","dependencies_parsed_at":"2022-08-25T21:10:56.692Z","dependency_job_id":null,"html_url":"https://github.com/dsfields/ordery-mongodb-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsfields%2Fordery-mongodb-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsfields%2Fordery-mongodb-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsfields%2Fordery-mongodb-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsfields%2Fordery-mongodb-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dsfields","download_url":"https://codeload.github.com/dsfields/ordery-mongodb-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246998104,"owners_count":20866690,"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":[],"created_at":"2024-10-06T18:11:58.993Z","updated_at":"2025-04-03T11:42:03.796Z","avatar_url":"https://github.com/dsfields.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ordery-mongodb\n\nConvert [`ordery.Order`](https://www.npmjs.com/package/ordery#orderyorder) instances into [MongoDB sort documents](https://docs.mongodb.com/manual/reference/method/cursor.sort/).\n\n__Table of Contents__\n\n* [Usage](#usage)\n* [API](#api)\n\n## Usage\n\nInstall `ordery-mongodb` as a dependency in your application:\n\n```sh\n$ npm install order-mongodb -S\n```\n\nUse it in  your application:\n\n```js\nconst ordery = require('ordery');\nconst ordongo = require('ordery-mongo');\n\nconst sort = order.parse('/foo:asc,/bar/baz:desc,/qux');\nconst mongoSort = ordongo.convert(sort);\n\nconsole.log(mongoSort);\n// {\n//   \"foo\": 1,\n//   \"bar.baz\": -1,\n//   \"qux\": 1\n// }\n```\n\n## API\n\nThe `ordery-mongodb` library provides a set of methods and classes for converting Ordery Expressions.\n\n### `ordongo.convert(expression [, strategy])`\n\nConverts a given Ordery Expression into a [MongoDB sort document](https://docs.mongodb.com/manual/reference/method/cursor.sort/).\n\n__Parameters__\n\n* `expression`: _(required)_ an instance of [`ordery.Order`](https://www.npmjs.com/package/ordery#orderyorder), or a string that can be parsed by `ordery`.\n\n* `strategy`: _(optional)_ an instance of [`Strategy`](#ordongostrategy).\n\n__Returns__\n\nAn object that represents the given Order Expression as a MongoDB sort document.\n\n### `ordongo.errors.DeniedFieldError`\n\nAn error thrown when an [`ordery.Order`](https://www.npmjs.com/package/ordery#orderyorder) instance is passed to [`convert()`](#ordongoconvertexpression-strategy) containing a black-listed field target.\n\n### `ordongo.errors.UnallowedFieldError`\n\nAn error thrown when an [`ordery.Order`](https://www.npmjs.com/package/ordery#orderyorder) instance is passed to [`convert()`](#ordongoconvertexpression-strategy) containing a field target that has not been white-listed.\n\n### `ordongo.errors.RequiredFieldError`\n\nAn error throw when an [`ordery.Order`](https://www.npmjs.com/package/ordery#orderyorder) instance is passed to [`convert()`](#ordongoconvertexpression-strategy) missing a required field.\n\n### `ordongo.Strategy`\n\nA class that represents a converstion stratgy.  Instances are meant to be cached in memory to prevent having to recompute this information with every call to [`convert()`](#ordongoconvertexpression-strategy).\n\n#### `Strategy.prototype.constructor([options])`\n\nCreate a new instance of `Strategy`.\n\n__Parameters__\n\n* `options`: _(optional)_ an object that provides conversion options.  This object can have the keys:\n\n  + `allow`: _(optional)_ an array of strings in [RFC 6901 JSON Pointer](https://tools.ietf.org/html/rfc6901) format specifying the field targets that are allowed to participate in an MongoDB sort.  This functions as a white list of allowable fields, and can only be present if `deny` is absent or empty.\n\n  + `deny`: _(optional)_ an array of strings in RFC 6901 JSON Pointer format specifying the field targets that are restricted from participating in an MongoDB sort.  This functions as a black list of allowable fields, and can only be present if `allow` is absent or empty.\n\n  + `require`: _(optional)_ an object that specifies required field target behavior.  This object can have the following keys:\n\n    - `fields`: _(optional)_ an array of strings in RFC 6901 JSON Pointer format specifying required fields targets in a given Ordery Expression.  If this key is ommitted or empty, there are assumed to be no required fields.\n\n    - `which`: _(optional)_ a string specifying which `fields` are required to be in a given Ordery Expression.  This can be either `any` or `all`.  If ommitted, this value defaults to `any`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsfields%2Fordery-mongodb-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdsfields%2Fordery-mongodb-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsfields%2Fordery-mongodb-node/lists"}