Search⌘ K
AI Features

Querying the Database

Explore methods to query MongoDB data in Spring Boot reactive applications by using query derivation and custom queries. Understand how to build search functionality beyond basic ID lookups to support real-world e-commerce needs such as partial matches and complex queries.

So far, we’ve both stored and retrieved data from MongoDB, but the process we’ve used isn’t the most optimal.

Looking things up by id isn’t ideal. After all, in a real-world e-commerce site, we can’t list our entire inventory and wait for the customer to select the item that way.

We need customers to enter criteria into a search box. Using the input, query the items collection. Let’s write a custom query.

Introduction to query derivation

Here’s what our search query interface looks like:

Java
public interface ItemRepository extends ReactiveCrudRepository<Item, String> {
Flux<Item> findByNameContaining(String partialName);
}
Item repository with custom finder

This ...