java - 在 Spingboot 应用程序中,简单的 Mongo DB 查询需要很长时间
问题描述
我有一个使用 MongoDB 作为数据库的 Springboot 应用程序。其中一个集合有一个字符串字段,对该字段的查询需要很长时间,我无法对其进行调整。我已经创建了索引,但仍然没有任何改进。这是我的代码。
public interface MyTableRepository extends MongoRepository<MyTable, String> {
public List<MyTable> findByState(String state);
}
这是我的索引:
db.getCollection('myTable').createIndex( { "state": 1 } )
当我从我的服务中运行以下代码时,此调用返回大约 800 行并且大约需要 20 秒。
List<MyTable> publishedItems = myRepository.findByState("published");
解决方案
推荐阅读
- c# - c# wpf中组合框的过滤
- json - 如何正确编写主题和订阅的 ARM 模板
- riscv - RISCV RV32IM:MULHSU - 哪个操作数是有符号的?
- javascript - ul li items shuffle 随机位置淡入淡出并一一
- html - 由于 CSS 的问题,没有出现弹出窗口
- windows - 有没有办法创建类似于 People App 的驻留在任务栏中的 Windows 10 应用程序?
- node.js - 当数据通过 websockets 不断更新时,我应该如何处理搜索?
- mysql - 如何使用插入的 ID 在同一个 MySQL 表中复制记录
- python - 如何找到没有重复数字的元素?
- c# - 尝试在 xamarin 表单中使用 admob 时获取“MediationRewardedVideoAdListenerImplementor 不是抽象的,并且不会覆盖抽象方法”