https://github.com/mhewedy/spring-data-jpa-mongodb-expressions
  
  
    Use the MongoDB query language to query your relational database, typically from frontend. 
    https://github.com/mhewedy/spring-data-jpa-mongodb-expressions
  
hibernate java jpa mongodb spring spring-boot spring-data-jpa
        Last synced: 21 days ago 
        JSON representation
    
Use the MongoDB query language to query your relational database, typically from frontend.
- Host: GitHub
- URL: https://github.com/mhewedy/spring-data-jpa-mongodb-expressions
- Owner: mhewedy
- License: apache-2.0
- Created: 2021-02-13T11:37:59.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-07-20T12:51:00.000Z (3 months ago)
- Last Synced: 2025-07-20T13:04:04.279Z (3 months ago)
- Topics: hibernate, java, jpa, mongodb, spring, spring-boot, spring-data-jpa
- Language: Java
- Homepage: https://mhewedy.github.io/spring-data-jpa-mongodb-expressions/
- Size: 1.56 MB
- Stars: 99
- Watchers: 9
- Forks: 19
- Open Issues: 0
- 
            Metadata Files:
            - Readme: README.md
- License: LICENSE
 
Awesome Lists containing this project
- awesome-java-zh - Spring Data JPA MongoDB Expressions - 允许您使用MongoDB查询语言来查询您的关系数据库。 (项目 / 数据库)
- fucking-awesome-java - Spring Data JPA MongoDB Expressions - Allows you to use MongoDB query language to query your relational database. (Projects / Database)
- awesome-java - Spring Data JPA MongoDB Expressions - Allows you to use MongoDB query language to query your relational database. (Projects / Database)
README
          # Spring Data JPA MongoDB Expressions
[](https://github.com/mhewedy/spring-data-jpa-mongodb-expressions/actions/workflows/maven.yml) 
[](https://codecov.io/gh/mhewedy/spring-data-jpa-mongodb-expressions)
[](https://javadoc.io/doc/com.github.mhewedy/spring-data-jpa-mongodb-expressions) 
[](https://gitter.im/spring-data-jpa-mongodb-expressions/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://twitter.com/intent/tweet?text=Use%20the%20MongoDB%20query%20syntax%20to%20query%20your%20relational%20database&url=https://github.com/mhewedy/spring-data-jpa-mongodb-expressions&via=Github&hashtags=java,springboot,mongodb,jpa,hibernate)
### How it works:
1. Customize JPA Repository base class:
    ```java
    @SpringBootApplication
    @EnableJpaRepositories(repositoryBaseClass = ExpressionsRepositoryImpl.class)
    public class Application { … }
    ```
2. Change your repository to extend `ExpressionsRepository`:
    ```java
    @Repository
    public interface EmployeeRepository extends ExpressionsRepository {
    }
    ```
3. Build the controller/service:
    ```java
    @PostMapping("/search")
    public ResponseEntity> search(@RequestBody Expressions expressions, Pageable pageable) {
        return ok().body(
                    employeeRepository.findAll(expressions, pageable).map(employeeMapper::toDto)
            );
    }
    ```
4. Send [Mongodb query in JSON](https://mhewedy.github.io/spring-data-jpa-mongodb-expressions/#_how_to_build_the_expressions) from frontend:
    ```json
    {
      "$or": [
        {"lastName": "ibrahim"},
        {
          "$and": [
            {"firstName": "mostafa"},
            {"birthDate": {"$gt": "1990-01-01"}}
          ]
        }
      ]
    }
    ```
### Learn more
For a quick start see [this Medium post](https://mohewedy.medium.com/using-mongodb-query-syntax-to-query-relational-database-in-java-57701f0b0f0)
 or [dev.to post](https://dev.to/mhewedy/using-mongodb-query-syntax-to-query-relational-database-in-java-49hf)
 or see [this demo example on Github](https://github.com/springexamples/spring-data-jpa-mongodb-expressions-demo).
See [documentation website](https://mhewedy.github.io/spring-data-jpa-mongodb-expressions/) for details about how to get started.
### Install:
For spring-boot 3.x:
    
```xml
  com.github.mhewedy
  spring-data-jpa-mongodb-expressions
  0.1.9
```
For spring-boot 2.x:
```xml
  com.github.mhewedy
  spring-data-jpa-mongodb-expressions
  0.0.8
```
#### 🎖 Special Thanks 
Special thanks to [Rashad Saif](https://github.com/rashadsaif) and [Hamada Elnoby](https://github.com/hamadaelnopy) for helping in the design, inspring with ideas, and for doing code review.
    
#### In the News
This repo has been mentioned in [spring.io](http://spring.io/blog/2021/07/06/this-week-in-spring-july-6th-2021) weekly news.