An OTP library to translate a special search query language (including aggregation) in MongoDB query.
Note: the queries are compatible with mongodb-erlang package.
E.g. select data where temperature>23 AND house is in Milano and pression <= 1015, ordered by house name ascending:
house.temperature>23 house.city:"Milano" house.pression<:1015 house.when>2017-12-15T10:20:00Z house.name-asc
Translated in the follow MongoDB query:
Query = {
  '$query', {
    '$and', [
      {<<"house.temperature">>, {'$gt', 23}},
      {<<"house.city">>, {'$eq', <<"Milano">>}},
      {<<"house.pression">>, {'$lte', 1015}},
      {<<"house.when">>, {'$gt', {1513, 333200, 0}}}
    ]
  },
  '$orderby', [
    {<<"house.name">>, 1}
  ]
},
mongopool_app:find(Pool, Table, Query).E.g. count how many times received a new log message today grouped by log level:
date > now-24h date-asc $group id: level count: $count(1)
Simple query:
MyQueryString = "house.temperature>23 house.city:\"Milano\" house.pression<:1015 house.when>2017-12-15T10:20:00Z house.when < now house.name-asc",
{ok, Query} = mongoql:parse(MyQueryString),
mongopool_app:find(Pool, Table, Query).Aggregation query:
MyAggString = "date > now-24h date-asc $group id: level count: $count(1)"
{ok, Agg} = mongoql:agg(MyAggString),
mongopool_app:command(Pool, TableInBinaryString, pipeline, Agg).| Op. | Name | Example | 
|---|---|---|
| < | Minor | temperature < 10.5 | 
| <: | Minor Equal | temperature <: 7.3 | 
| : | Equal | temperature : 5orname : "FuuBar" | 
| >: | Major Equal | temperature >: 2 | 
| > | Major | temperature > 4.4 | 
| !: | Not Equal | temperature !: 4orname !: "FuuBar" | 
| ~ | Regex | name ~ "Mi*" | 
| in | In | temperature in [16 17 18]orcity in ["Milano" "Roma"] | 
| not | Not | not temperature > 5ornot name in ["Milano" "Roma"] | 
| exists | Exists*(#) | name existsornot name exists | 
| {name}-asc | Order Ascending | name-asc | 
| {name}-desc | Order Descending | name-desc | 
(#) matches the documents that contain the field.
| Type | Example | 
|---|---|
| Integer | 15,-23,543 | 
| Float | 34.56,-235.32 | 
| String | "Hello world!" | 
| Datetime | 2016-01-15T18:19:28Z(Note: without doublequote) | 
| Datetime | now(automatically translated with now datetime of the server | 
| Datetime | now - 1h,now - 1m,now - 1s | 
$ ./utils/rebar3 compile