I have a MongoDB collection (called "Products") of ~7000 documents, hosted on a Mongo Atlas shared cluster, looking somewhat like this:
{
identifier: 123,
archived: true,
/* Some other properties.. */
}
Attempting to run simple queries on the above collection in a manner such as:
mongoTemplate.find(
new Query().addCriteria(Criteria.where("archived").is(false)),
Product.class,
"Products");
leads to an extremely high execution time, 8~9 seconds on both the local instance as well as deployed (Heroku) version. However, when running the same query directly from the MongoRepository<>
, e.g.
repository.findByArchived(false)
, the query runs almost instantaneously (as it would do in the mongo CLI).
Am I missing out some additional configuration that is preventing mongoTemplate
from running queries in a smoother manner like the pre-configured MongoRepository
(e.g. some bson/POJO encoding)? Any help on this would be greatly appreciated!