com.github.borsch:rsql-mongodb

Parent pom providing dependency and plugin management for applications built with Maven

License

License

MIT
Categories

Categories

MongoDB Data Databases
GroupId

GroupId

com.github.borsch
ArtifactId

ArtifactId

rsql-mongodb
Last Version

Last Version

1.1
Release Date

Release Date

Type

Type

jar
Description

Description

Parent pom providing dependency and plugin management for applications built with Maven
Source Code Management

Source Code Management

http://github.com/borsch/rsql-mongodb

Download rsql-mongodb

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.borsch/rsql-mongodb/ -->
<dependency>
    <groupId>com.github.borsch</groupId>
    <artifactId>rsql-mongodb</artifactId>
    <version>1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.borsch/rsql-mongodb/
implementation 'com.github.borsch:rsql-mongodb:1.1'
// https://jarcasting.com/artifacts/com.github.borsch/rsql-mongodb/
implementation ("com.github.borsch:rsql-mongodb:1.1")
'com.github.borsch:rsql-mongodb:jar:1.1'
<dependency org="com.github.borsch" name="rsql-mongodb" rev="1.1">
  <artifact name="rsql-mongodb" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.borsch', module='rsql-mongodb', version='1.1')
)
libraryDependencies += "com.github.borsch" % "rsql-mongodb" % "1.1"
[com.github.borsch/rsql-mongodb "1.1"]

Dependencies

compile (3)

Group / Artifact Type Version
org.springframework.data : spring-data-commons jar
org.springframework.boot : spring-boot-starter-data-mongodb jar 2.3.2.RELEASE
cz.jirutka.rsql : rsql-parser jar 2.1.0

test (2)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.3.2.RELEASE
com.google.guava : guava jar 29.0-jre

Project Modules

There are no modules declared in this project.

Defunct

This library has been superseded by the more general (and just better) rest-query-engine.

Java CI with Maven

What

An open source implementation for converting rsql to mongo queries for spring data. RSQL is a flexible and readable query language based off of apache's FIQL. Providing this adapater for mongo queries makes RSQL a natural choice for APIs that want to provide flexible querying and whose underlying datastore is mongodb.

How to use it

Add maven dependency

<dependency>
    <groupId>com.github.borsch</groupId>
    <artifactId>rsql-mongodb</artifactId>
    <version>1.1</version>
</dependency>
@Autowired
private MongoOperations mongoOperations;

@Autowired
private MongoMappingContext mappingContext;

// build the converter. You can define a list of conversions instead, but using a spring conversion service and mongo mapping context
// works really quite well. Some applications will have a conversion service available from the application context that can include
// custom converters (iso -> date, etc)
ComparisonToCriteriaConverter converter = new ComparisonToCriteriaConverter(new DefaultConversionService(), mongoMappingContext);

// build the actual rsql string -> mongo criteria adapter
RsqlMongoAdapter adapter = new RsqlMongoAdapter(converter);

// convert the rsql to some criteria and add that criteria to the mongo query object
Query query = Query.query(adapter.getCriteria("firstName==joe", Person.class));

// make your query!
List<Person> personsNamedJoe = mongoOperations.find(query, Person.class);

Examples of supported cases. For the full list, please see tests.

# basic equality
firstName==joe -> { "firstName" : "joe"}

# basic inequality
firstName!=joe -> { "firstName" : { "$ne" : "joe"}}

# basic greater than
createDate=gt=300 -> { "createDate" : { "$gt" : 300}}

# basic greater than or equal
createDate=ge=300 -> { "createDate" : { "$gte" : 300}}

# basic less than
createDate=lt=300 -> { "createDate" : { "$lt" : 300}}

# basic less than or equal
createDate=le=300 -> { "createDate" : { "$lte" : 300}}

# basic element appears in list
firstName=in=(billy,bob,joel) -> { "firstName" : { "$in" : [ "billy" , "bob" , "joel"]}}

# basic element does not appear in list
firstName=out=(billy,bob,joel) -> { "firstName" : { "$nin" : [ "billy" , "bob" , "joel"]}}

# anding of two basic conditions
firstName!=joe;lastName==dummy -> { "$and" : [ { "firstName" : { "$ne" : "joe"}} , { "lastName" : "dummy"}]}

# oring of two basic conditions
firstName!=john,lastName==doe -> { "$or" : [ { "firstName" : { "$ne" : "john"}} , { "lastName" : "doe"}]}

# anding of two oring conditions of anding conditions
((firstName==john;lastName==doe),(firstName==aaron;lastName==carter));((age==21;height==90),(age==30;height==100)) -> 

    {
       "$and":[
          {
             "$or":[
                {
                   "$and":[
                      {
                         "firstName":"john"
                      },
                      {
                         "lastName":"doe"
                      }
                   ]
                },
                {
                   "$and":[
                      {
                         "firstName":"aaron"
                      },
                      {
                         "lastName":"carter"
                      }
                   ]
                }
             ]
          },
          {
             "$or":[
                {
                   "$and":[
                      {
                         "age":21
                      },
                      {
                         "height":90
                      }
                   ]
                },
                {
                   "$and":[
                      {
                         "age":30
                      },
                      {
                         "height":100
                      }
                   ]
                }
             ]
          }
       ]
    }
    

License

This project is licensed under MIT license.

Versions

Version
1.1
1.0