0

Is there any way to modify every query prepared by mongotemplate.find spring boot 2?

I want to modify every find query prepared by spring data mongo find . I want to add custom query after every find query to mongo.

How can I achieve that in spring boot 2.

  • More details on what you're looking to do? Do you want to supplement a query with more criteria to limit results? Run another query after each query? Give some more details about your specific case so SO can be of more help to you – Dovmo Aug 12 '18 at 04:25

3 Answers3

0

I want to override find methods of mongo template with my own implementation and want to add some custom query on top of find query which was built by crud repository methods.

0

I want to add some custom query by overriding methods of mongotemplate to every find method of crud repository

0

you would need to customize the repository class implementation for the mongoDB.

below is the sample code to help you understand how to add customized query in the repository. you would need to twik the code as per your requirement after getting the result.

public interface PersonRepository extends PagingAndSortingRepository<Person, String> {

List<Person> findByLastname(String lastname);

Page<Person> findByFirstname(String firstname, Pageable pageable);

Person findByShippingAddresses(Address address);

}

you can visit this page for proper understanding https://docs.spring.io/spring-data/mongodb/docs/1.2.0.RELEASE/reference/html/mongo.repositories.html

Abhishek kumar
  • 148
  • 1
  • 2