0

I was trying to measure how long it took for this simple query to execute:

companyRepository.findOne(companyId); // took 300ms

Here is the repository class I use:

package fn.repository;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import fn.model.Company;

@RepositoryRestResource(exported = false)
public interface CompanyRepository extends MongoRepository<Company, String>, QueryDslPredicateExecutor<Company> {
}

Is it normal to take this long for an indexed lookup?

user1955934
  • 3,185
  • 5
  • 42
  • 68

1 Answers1

0

It is normal. Inserting/Updating into database which have indexes ought to take more time than simply writing into heap structure because than database has to maintain order and balance the tree (MongoDB uses B-Tree data structure for index implementation like any other database systems). To follow: https://docs.mongodb.org/manual/core/indexes-introduction/#single-field

The best way to reduce operational time is to create indexes on single field of a document which you probably want to sort/search on rather than indexing on many non required fields.

Istiak Morsalin
  • 10,621
  • 9
  • 33
  • 65