zebzhao / Angular-QueryBuilder

A modernized Angular 4+ query builder based on jquery QueryBuilder
MIT License
292 stars 222 forks source link

Mongodb query output #205

Open Blackbaud-JasonBodnar opened 3 years ago

Blackbaud-JasonBodnar commented 3 years ago

jQuery-QueryBuilder has plugins that allow the output type to be SQL or a Mongodb query. Is it possible to use those plugins with this project? Or is there another way to get a language-specific output?

I found a java library that converts the jQuery-QueryBuilder output to either SQL or Mongodb (https://github.com/itfsw/QueryBuilder/blob/master/README-EN.md) but when I take the output from this component and try to convert it to Mongodb it fails.

The simple output I get from this component is:

{
  "condition": "and",
  "rules": [
    {
      "field": "amount",
      "operator": ">",
      "value": 1000
    }
  ]
}

If I change it up by hand to somewhat match the example given by the above library it works:

{
   "condition": "and", 
        "rules": [
            {
               "field": "amount", 
               "type": "string" ,
               "input": "text", 
               "operator": "greater",
               "value": 1000
             }
      ]
}

I had to add "type": "string" and "input": "text" and change operator from > to greater.

Are there any config options to get those fields included and swap the operator?

verti-go commented 3 years ago

This is a parser I *began creating to convert those rules to those compatible with json-rules-engine.

https://github.com/ng-druid/platform/blob/master/modules/pages/src/lib/services/rules-parser.service.ts

I plan on doing the same for elastic since its a critical part of my stack.

The dream would be to build queries using this interface and convert them to anything like Mongo using an adaptor.