{"id":18489105,"url":"https://github.com/hachreak/mongoql","last_synced_at":"2025-04-08T21:30:41.549Z","repository":{"id":139147368,"uuid":"49828182","full_name":"hachreak/mongoql","owner":"hachreak","description":"An OTP library to convert a easy-to-use textual search-engine-like query language in a MongoDB query.","archived":false,"fork":false,"pushed_at":"2019-05-18T15:47:54.000Z","size":1827,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T18:06:30.340Z","etag":null,"topics":["erlang","erlang-libraries","erlang-library","mongodb","mongodb-query","query-language"],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hachreak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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":"2016-01-17T17:43:30.000Z","updated_at":"2022-05-25T20:53:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"cdb4b740-b4e7-4c95-ba60-027242b95aa0","html_url":"https://github.com/hachreak/mongoql","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/hachreak%2Fmongoql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hachreak%2Fmongoql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hachreak%2Fmongoql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hachreak%2Fmongoql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hachreak","download_url":"https://codeload.github.com/hachreak/mongoql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247931023,"owners_count":21020151,"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":["erlang","erlang-libraries","erlang-library","mongodb","mongodb-query","query-language"],"created_at":"2024-11-06T12:55:17.387Z","updated_at":"2025-04-08T21:30:41.544Z","avatar_url":"https://github.com/hachreak.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"mongoql\n=======\n\n[![Build Status](https://travis-ci.org/hachreak/mongoql.svg?branch=master)](https://travis-ci.org/hachreak/mongoql)\n\nAn OTP library to translate a special search query language\n(including aggregation) in MongoDB query.\n\nNote: the queries are compatible with\n[mongodb-erlang](https://github.com/comtihon/mongodb-erlang) package.\n\nExamples Query\n--------------\n\nE.g. select data where temperature\u003e23 AND house is in Milano and\npression \u003c= 1015, ordered by house name ascending:\n\n```\nhouse.temperature\u003e23 house.city:\"Milano\" house.pression\u003c:1015 house.when\u003e2017-12-15T10:20:00Z house.name-asc\n```\n\nTranslated in the follow MongoDB query:\n\n```erlang\nQuery = {\n  '$query', {\n    '$and', [\n      {\u003c\u003c\"house.temperature\"\u003e\u003e, {'$gt', 23}},\n      {\u003c\u003c\"house.city\"\u003e\u003e, {'$eq', \u003c\u003c\"Milano\"\u003e\u003e}},\n      {\u003c\u003c\"house.pression\"\u003e\u003e, {'$lte', 1015}},\n      {\u003c\u003c\"house.when\"\u003e\u003e, {'$gt', {1513, 333200, 0}}}\n    ]\n  },\n  '$orderby', [\n    {\u003c\u003c\"house.name\"\u003e\u003e, 1}\n  ]\n},\nmongopool_app:find(Pool, Table, Query).\n```\n\nExample Aggregation\n-------------------\n\nE.g. count how many times received a new log message today\ngrouped by log level:\n\n```\ndate \u003e now-24h date-asc $group id: level count: $count(1)\n```\n\nHow to use\n----------\n\nSimple query:\n\n```erlang\nMyQueryString = \"house.temperature\u003e23 house.city:\\\"Milano\\\" house.pression\u003c:1015 house.when\u003e2017-12-15T10:20:00Z house.when \u003c now house.name-asc\",\n{ok, Query} = mongoql:parse(MyQueryString),\nmongopool_app:find(Pool, Table, Query).\n```\n\nAggregation query:\n\n```erlang\nMyAggString = \"date \u003e now-24h date-asc $group id: level count: $count(1)\"\n{ok, Agg} = mongoql:agg(MyAggString),\nmongopool_app:command(Pool, TableInBinaryString, pipeline, Agg).\n```\n\nOperators\n---------\n\nOp.            | Name             | Example\n---------------|------------------|------------------------------------------\n`\u003c`            | Minor            | `temperature \u003c 10.5`\n`\u003c:`           | Minor Equal      | `temperature \u003c: 7.3`\n`:`            | Equal            | `temperature : 5` or `name : \"FuuBar\"`\n`\u003e:`           | Major Equal      | `temperature \u003e: 2`\n`\u003e`            | Major            | `temperature \u003e 4.4`\n`!:`           | Not Equal        | `temperature !: 4` or `name !: \"FuuBar\"`\n`~`            | Regex            | `name ~ \"Mi*\"`\n`in`           | In               | `temperature in [16 17 18]` or `city in [\"Milano\" \"Roma\"]`\n`not`          | Not              | `not temperature \u003e 5` or `not name in [\"Milano\" \"Roma\"]`\n`exists`       | Exists*(#)       | `name exists` or `not name exists`\n`{name}-asc`   | Order Ascending  | `name-asc`\n`{name}-desc`  | Order Descending | `name-desc`\n\n\n(#) matches the documents that contain the field.\n\nTypes supported\n---------------\n\nType     | Example\n---------|----------------------\nInteger  | `15`, `-23`, `543`\nFloat    | `34.56`, `-235.32`\nString   | `\"Hello world!\"`\nDatetime | `2016-01-15T18:19:28Z` (Note: without doublequote)\nDatetime | `now` (automatically translated with now datetime of the server\nDatetime | `now - 1h`, `now - 1m`, `now - 1s`\n\n\nBuild\n-----\n\n    $ ./utils/rebar3 compile\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhachreak%2Fmongoql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhachreak%2Fmongoql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhachreak%2Fmongoql/lists"}