{"id":13607611,"url":"https://github.com/mongodb-js/mongodb-language-model","last_synced_at":"2025-04-12T14:30:43.537Z","repository":{"id":33782109,"uuid":"37444365","full_name":"mongodb-js/mongodb-language-model","owner":"mongodb-js","description":"Parses MongoDB query language and creates hierarchical Ampersand.js models to interact with the query tree","archived":true,"fork":false,"pushed_at":"2021-05-09T22:51:37.000Z","size":1092,"stargazers_count":33,"open_issues_count":5,"forks_count":10,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-11-07T13:36:59.860Z","etag":null,"topics":["ampersand","compass-tools","mongodb","mongodb-query","parser"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mongodb-js.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":"2015-06-15T04:56:22.000Z","updated_at":"2024-09-09T01:39:03.000Z","dependencies_parsed_at":"2022-09-06T20:32:03.630Z","dependency_job_id":null,"html_url":"https://github.com/mongodb-js/mongodb-language-model","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-js%2Fmongodb-language-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-js%2Fmongodb-language-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-js%2Fmongodb-language-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-js%2Fmongodb-language-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongodb-js","download_url":"https://codeload.github.com/mongodb-js/mongodb-language-model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248581001,"owners_count":21128091,"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":["ampersand","compass-tools","mongodb","mongodb-query","parser"],"created_at":"2024-08-01T19:01:20.107Z","updated_at":"2025-04-12T14:30:43.282Z","avatar_url":"https://github.com/mongodb-js.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# mongodb-language-model\n\n[![build status](https://secure.travis-ci.org/mongodb-js/mongodb-language-model.png)](http://travis-ci.org/mongodb-js/mongodb-language-model)\n\nParses a MongoDB query and creates an abstract syntax tree (AST) with part of speech\ntagging. Currently, only [strict extended json][docs-extended-json] syntax is\nsupported (which means keys have to be surrounded by double quotes and values\nhave to match the strict syntax of the extended-json format.);\n\n## Usage\n\nThe main module exposes two functions: `accepts(queryStr)` and `parse(queryStr)`.\n\n#### `accepts(queryStr)`\n\nThe `accepts(queryStr)` function takes a query string and returns `true` if the\nstring is a valid MongoDB query, `false` otherwise.\n\nExample:\n\n```javascript\nvar accepts = require('mongodb-language-model').accepts;\nvar assert = require('assert');\n\nassert.ok(accepts('{\"foo\": 1}'));\nassert.ok(accepts('{\"age\": {\"$gt\": 35}}'));\nassert.ok(accepts('{\"$or\": [{\"email\": {\"$exists\": true}}, {\"phone\": {\"$exists\": true}}]}'));\n\nassert.equal(accepts('{\"$invalid\": \"key\"}'), false);\n```\n\n#### `parse(queryStr)`\n\nThe `parse(queryStr)` function takes a query string and returns an abstract\nsyntax tree (AST) as a javascript object, if the query is valid. If the\nquery is not valid, the function throws a `pegjs.SyntaxError` with a message\nexplaining the failure.\n\nExample:\n\n```javascript\nvar parse = require('mongodb-language-model').parse;\nvar assert = require('assert');\nvar pegjs = require('pegjs');\n\nvar ast = parse('{\"foo\": \"bar\"}');\nassert.deepEqual(ast, {\n  'pos': 'expression',\n  'clauses': [\n    {\n      'pos': 'leaf-clause',\n      'key': 'foo',\n      'value': {\n        'pos': 'leaf-value',\n        'value': 'bar'\n      }\n    }\n  ]\n});\n```\n\n## UML diagram\n\nThis is the hierarchical model that is created when a query is parsed:\n\n![](./docs/query_language_uml.png)\n\n\n\n## Installation\n\n```\nnpm install --save mongodb-language-model\n```\n\n## Testing\n\n```\nnpm test\n```\n\n## License\n\nApache 2.0\n\n[docs-extended-json]: https://docs.mongodb.com/manual/reference/mongodb-extended-json/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-js%2Fmongodb-language-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongodb-js%2Fmongodb-language-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-js%2Fmongodb-language-model/lists"}