0

I have a Springboot App that is using MongoDB as the database. One of the collections has a string field and query on that field is taking very long, I am unable to tune it. I have created index but still there is no improvement. Here is my code.

public interface MyTableRepository extends MongoRepository<MyTable, String> {
    public List<MyTable> findByState(String state);
}

Here is my index:

db.getCollection('myTable').createIndex( { "state": 1 } )

When I run the following code form my service, this call returns about 800 rows & takes about 20 seconds.

List<MyTable> publishedItems = myRepository.findByState("published");
rtnyc
  • 145
  • 1
  • 2
  • 10
  • Size of `MyTable` might affect? Do you need all entity? Can you try to fetch only a single column & compare the time? Also `state` seems like an `enum`, why not just create & use a `MyTableState` enum class and use it? I think should be helpful both in size & comparison speed, though indexing should help with that as well – buræquete Jul 12 '19 at 03:24
  • Have you thought about caching the method , it will save a lot of time and requests to the mongoDb. – Ananthapadmanabhan Jul 12 '19 at 05:20

0 Answers0