Allows you to use the MongoDB query syntax to query your relational database.

Overview

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 { … }
  1. Change your repository to extends ExpressionsRepository:
@Repository
public interface EmployeeRepository extends ExpressionsRepository<Employee, Long> {
}
  1. 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)
        );
}
  1. Send Mongodb query in JSON from frontend: image

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.0.4</version>
</dependency>

🎖 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.

Comments
  • Support UUID type

    Support UUID type

    I'm trying to use the plugin to search some UUID fields but it looks like the fields are not properly translated from the request string to JPA UUID

    Am I missing something?

    opened by Yak000 3
  • Parent type being reported in case of invalid field

    Parent type being reported in case of invalid field

    Actual: Unable to locate Attribute with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Auditable] Expected: Unable to locate Attribute with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Employee]

    full stack trace:

    2021-04-23 04:47:06.553  INFO 42381 --- [           main] o.s.t.c.transaction.TransactionContext   : Rolled back transaction for test: [DefaultTestContext@524d6d96 testClass = ExpressionsRepositoryImplTest, testInstance = com.github.mhewedy.expressions.ExpressionsRepositoryImplTest@11bd0f3b, testMethod = testInvalidFieldName@ExpressionsRepositoryImplTest, testException = java.lang.AssertionError: 
    Expecting:
     <"Unable to locate Attribute  with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Auditable]; nested exception is java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Auditable]">
    to contain:
     <"ManagedType [com.github.mhewedy.expressions.Employee]"> , mergedContextConfiguration = [MergedContextConfiguration@152aa092 testClass = ExpressionsRepositoryImplTest, locations = '{}', classes = '{class org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, class org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper=true}', contextCustomizers = set[[ImportsContextCustomizer@44a7bfbc key = [@org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa(), @org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestEntityManager(), @org.springframework.data.jpa.repository.config.EnableJpaRepositories(repositoryBaseClass=class com.github.mhewedy.expressions.ExpressionsRepositoryImpl, enableDefaultTransactions=true, excludeFilters=[], basePackageClasses=[], escapeCharacter=\, includeFilters=[], bootstrapMode=DEFAULT, repositoryFactoryBeanClass=class org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean, queryLookupStrategy=CREATE_IF_NOT_FOUND, entityManagerFactoryRef=entityManagerFactory, namedQueriesLocation=, transactionManagerRef=transactionManager, basePackages=[com.github.mhewedy.expressions], repositoryImplementationPostfix=Impl, considerNestedRepositories=false, value=[]), @org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase(replace=ANY, connection=NONE), @org.apiguardian.api.API(consumers=[*], since=5.0, status=STABLE), @org.springframework.boot.test.autoconfigure.core.AutoConfigureCache(cacheProvider=NONE), @org.springframework.boot.autoconfigure.domain.EntityScan(basePackages=[], value=[com.github.mhewedy.expressions], basePackageClasses=[]), @org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters(value=[class org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTypeExcludeFilter]), @org.springframework.context.annotation.Import(value=[class org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelector]), @org.springframework.test.context.ContextConfiguration(inheritInitializers=true, initializers=[], loader=interface org.springframework.test.context.ContextLoader, classes=[class org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, class org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration], name=, locations=[], value=[], inheritLocations=true), @org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase(replace=ANY, connection=H2), @org.springframework.transaction.annotation.Transactional(propagation=REQUIRED, rollbackForClassName=[], transactionManager=, isolation=DEFAULT, timeoutString=, readOnly=false, label=[], noRollbackFor=[], noRollbackForClassName=[], value=, timeout=-1, rollbackFor=[]), @org.springframework.boot.autoconfigure.ImportAutoConfiguration(value=[], exclude=[], classes=[]), @org.junit.jupiter.api.extension.ExtendWith(value=[class org.springframework.test.context.junit.jupiter.SpringExtension]), @org.springframework.context.annotation.Import(value=[class org.springframework.boot.autoconfigure.domain.EntityScanPackages$Registrar]), @org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper), @org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration(enabled=false), @org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest(bootstrapMode=DEFAULT, useDefaultFilters=true, excludeFilters=[], showSql=true, excludeAutoConfiguration=[], includeFilters=[], properties=[]), @org.springframework.boot.test.autoconfigure.properties.PropertyMapping(value=spring.test.database, skip=NO), @org.springframework.context.annotation.Import(value=[class org.springframework.data.jpa.repository.config.JpaRepositoriesRegistrar])]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@175c2241, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@776aec5c, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@4c12331b, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@1573f9fc, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@d646b630, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@489115ef, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@0], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.event.ApplicationEventsTestExecutionListener.recordApplicationEvents' -> false]]
    
    java.lang.AssertionError: 
    Expecting:
     <"Unable to locate Attribute  with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Auditable]; nested exception is java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [invalidFieldName] on this ManagedType [com.github.mhewedy.expressions.Auditable]">
    to contain:
     <"ManagedType [com.github.mhewedy.expressions.Employee]"> 
    
    	at com.github.mhewedy.expressions.ExpressionsRepositoryImplTest.testInvalidFieldName(ExpressionsRepositoryImplTest.java:277)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    
    
    enhancement 
    opened by mhewedy 3
  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

    opened by gitter-badger 1
  • Support projections

    Support projections

    Currently, spring-data-jpa-mongodb-expressions library doesn't support projection. (limitation by spring-data-jpa see https://github.com/spring-projects/spring-data-jpa/issues/1378).

    Hopefully they fix it, so projection would be supported here as well.

    enhancement 
    opened by mhewedy 1
  • Support HijrahDate

    Support HijrahDate

    org.springframework.dao.InvalidDataAccessApiUsageException: 
    Parameter value [Hijrah-umalqura AH 1443-05-10] did not match expected type [java.time.chrono.HijrahDate (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [Hijrah-umalqura AH 1443-05-10] did not match expected type [java.time.chrono.HijrahDate (n/a)]
    
    enhancement 
    opened by mhewedy 0
  • fix issue of is null of many-to-one associations

    fix issue of is null of many-to-one associations

    Supporting the case when an Employee entity has ManyToOne association with Departement and we need to fetch employees that have no departments, the json looks like:

    {
      "department": null
    }
    

    previously, it was returning some exception Unable to locate attribute with the given name....

    opened by mhewedy 0
  • add regex operator

    add regex operator

    it will require some work on different databases

    e.g. postgresql : https://www.postgresql.org/docs/9.3/functions-matching.html oracle : https://docs.oracle.com/cd/B12037_01/server.101/b10759/conditions018.htm mysql: https://dev.mysql.com/doc/refman/8.0/en/pattern-matching.html

    how to customize in jpa criteria: https://stackoverflow.com/questions/24995881/use-regular-expressions-in-jpa-criteriabuilder

    opened by mhewedy 0
  • prevent creating join more than once

    prevent creating join more than once

    Example input:

    {
      "lastName": "ibrahim",
      "department.id": 10,
      "department.name": "hr"
    }
    

    Expected SQL:

    .....
    from employee employee0_ inner join department department1_ on employee0_.department_id=department1_.id 
    where employee0_.last_name=? and department1_.id=? and department2_.name=?
    

    Actual SQL:

    .......
    from employee employee0_ inner join department department1_ on employee0_.department_id=department1_.id 
    inner join department department2_ on employee0_.department_id=department2_.id 
    where employee0_.last_name=? and department1_.id=? and department2_.name=?
    

    notice the duplicate join on the 2nd line above

    bug 
    opened by mhewedy 0
Releases(v0.0.5)
  • v0.0.4(Sep 19, 2021)

  • v0.0.3(Jul 25, 2021)

    Adding new features and bugfixes:

    #23 Add public api in the Expression object to accept boolean parameters #21 fix issue of is null of many-to-one associations #17 support enum for $in and $nin operators #15 add count(Expressions) method #13 Allow using like operator ($contains ...) with numeric properties #11 support Embedded values #9 Parent type being reported in case of invalid field enhancement #6 prevent creating join more than once

    Source code(tar.gz)
    Source code(zip)
Owner
Muhammad Hewedy
Software Developer/Architect
Muhammad Hewedy
Relational database project, PC Builder, for the Database Systems Design course.

README: Starting the Progam: This program was built and ran on the Eclipse IDE. To run, first create the database, "ty_daniel_db", using the ty_dani

Daniel Ty 1 Jan 6, 2022
Spring Boot & MongoDB Login and Registration example with JWT, Spring Security, Spring Data MongoDB

Spring Boot Login and Registration example with MongoDB Build a Spring Boot Auth with HttpOnly Cookie, JWT, Spring Security and Spring Data MongoDB. Y

null 15 Dec 30, 2022
Dynamically filters JPA entities with a simple query syntax. Provides JPA/Hibernate predicates and Spring Data specifications.

Spring Filter You need a way to dynamically filter entities without any effort? Just add me to your pom.xml. Your API will gain a full featured search

Turkraft 142 Dec 13, 2022
Tuya 37 Dec 26, 2022
DM Movie is an app with several movies catalogued through a database, you enter your email and your rating of the movie

DM Movie is an app with several movies catalogued through a database, you enter your email and your rating of the movie

Davi M. G. de Almeida 5 Jan 28, 2022
Spring JPA @Query for custom query in Spring Boot example

Spring JPA @Query example (Custom query) in Spring Boot Use Spring JPA @Query for custom query in Spring Boot example: Way to use JPQL (Java Persisten

null 17 Dec 3, 2022
A minecraft minigame where you have to defend your bed and destroy the others. Once your bed is destroyed, you cannot respawn.

As from November 1st 2021 BedWars1058 by Andrei Dascălu becomes open source under GNU GPL 3.0 license. If you are a developer I would really appreciat

Andrei Dascălu 182 Dec 26, 2022
A Pomodoro Timer that allows you to collect Pokemon as you work.

Pomodoro: The Pokémon Collecting Game! A fun take on the Pomodoro Technique So, what does this application do? This application utilizes the famous Po

Kevin Wong 2 Jan 29, 2022
Android library that allows you to determine your location in a few of lines!

locsimple Android library that allows you to determine your location in some lines! Benefits: automatic processing of permissions processing of enabli

Dmitry 7 Aug 31, 2022
A mod for OneConfig that allows you to customize the hit color of any living entity to your liking.

HitColor A mod for OneConfig that allows you to customize the hit color of any living entity to your liking. Features An option to toggle Armor being

Nox 4 Nov 5, 2022
A Java agent that disables platform features you don't use, before an attacker uses them against you.

aegis4j Avoid the NEXT Log4Shell vulnerability! The Java platform has accrued a number of features over the years. Some of these features are no longe

Daniel Gredler 14 Jan 11, 2022
"Some" Utilities you can use for your Java projects "freely"! Files are compiled with Java-8 and above, but mostly Java-11.

✨ Java-SomeUtils ?? "Some" Utilities you can use for your Java projects "freely"! *"Freely"* forcing you to include the license into your program. Fil

JumperBot_ 2 Jan 6, 2023
mall学习教程,架构、业务、技术要点全方位解析。mall项目(40k+star)是一套电商系统,使用现阶段主流技术实现。涵盖了SpringBoot 2.3.0、MyBatis 3.4.6、Elasticsearch 7.6.2、RabbitMQ 3.7.15、Redis 5.0、MongoDB 4.2.5、Mysql5.7等技术,采用Docker容器化部署。

mall学习教程 简介 mall学习教程,架构、业务、技术要点全方位解析。mall项目(40k+star)是一套电商系统,使用现阶段主流技术实现。涵盖了SpringBoot 2.3.0、MyBatis 3.4.6、Elasticsearch 7.6.2、RabbitMQ 3.7.15、Redis 5

macro 11.7k Jan 8, 2023
Springboot CRUD api using containerized mongoDB. ☕🍃📦

Javongo ☕ ?? Springboot CRUD api using containerized mongoDB. Feel free to use it as an example for your projects. Running Make sure ports 27017 & 808

Antonio Cituk 8 Mar 19, 2022
CRUD operation using java springboot microservice hosted in kubernetes env, data stored in mongodb

springboot-mongodb-k8s-parth Brief Introduction Hello Friends, I have created REST API using Springboot and Spring cloud application which performs CR

Parth Shah 1 Nov 11, 2021
Ferramenta de Gerenciamento de Projetos de Software utilizando a metodologia Ágil Scrum e Gamification com Webflux e Mongodb

Task Flow Application Getting started To make it easy for you to get started with GitLab, here's a list of recommended next steps. Already a pro? Just

Rodolfo Gonçalves de Luna Freire 1 Oct 22, 2021
How to configure Replica Set with Embedded Mongo using Spring Boot and Flapdoodle for unit testing code that uses mongodb transactions

Spring Boot Embedded Mongo with Replica Set This project defines a basic rest service that allows users to update records of a Person (name and email)

Divyansh Shekhar Gaur 4 Nov 1, 2022
My solutions for the MongoDB for Java Developers course

Welcome to M220J Disclaimer: The dependencies and versions in this project are not maintained. This project is intended for educational purposes and i

Salih Candir 3 Jun 26, 2022
Deploying Spring Boot and MongoDB as Containers Using Docker and Docker Compose

springboot-mongodb-docker Deploying Spring Boot and MongoDB as Containers Using Docker and Docker Compose Steps & Commands pull mongo image from docke

Java Techie 9 Nov 25, 2022