Skip to content

mhewedy/spring-data-jpa-mongodb-expressions

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Spring Data JPA MongoDB Expressions

Java CI with Maven codecov javadoc Join the chat at https://gitter.im/spring-data-jpa-mongodb-expressions/community Tweet

How it works:

  1. Customize JPA Repository base class:

    @SpringBootApplication
    @EnableJpaRepositories(repositoryBaseClass = ExpressionsRepositoryImpl.class)
    public class Application { … }
  2. Change your repository to extends ExpressionsRepository:

    @Repository
    public interface EmployeeRepository extends ExpressionsRepository<Employee, Long> {
    }
  3. Build the controller/service:

    @PostMapping("/search")
    public ResponseEntity<Page<EmployeeDto>> search(@RequestBody Expressions expressions, Pageable pageable) {
    
        return ok().body(
                    employeeRepository.findAll(expressions, pageable).map(employeeMapper::toDto)
            );
    }
  4. Send Mongodb query in JSON from frontend:

    {
      "$or": [
        {"lastName": "ibrahim"},
        {
          "$and": [
            {"firstName": "mostafa"},
            {"birthDate": {"$gt": "1990-01-01"}}
          ]
        }
      ]
    }

    Learn more

    For quick start see this Medium post or dev.to post or see this demo example on Github.

    See documentation website for details about how to get started.

    Install:

    <dependency>
      <groupId>com.github.mhewedy</groupId>
      <artifactId>spring-data-jpa-mongodb-expressions</artifactId>
      <version>0.1.0</version>
    </dependency>
    

    Note: Starting from version 0.1.0 the library supports springboot 3, to use the library with springboot 2 use versions 0.0.x e.g. version 0.0.5.

    πŸŽ– Special Thanks

    Special thanks to Rashad Saif and Hamada Elnoby for helping in the design, inspring with ideas, and for doing code review.

    Next Release

    See List of issues to be shipped in the next release

    In the News

    This repo has mentioned in spring.io weekly news.

    Online Validator

    see https://expressions-validator.fly.dev/ to help validate expressions