【发布时间】:2013-08-30 09:28:55
【问题描述】:
我需要一些关于如何使用 mongodb 正确设置索引的建议。
假设我的数据收集是这样的:
玩家
- age
- scores
- fouls
- yellow cards
- red cards
- offsides
我的问题是我的潜在查询可以涵盖所有索引组合,例如:
Get players that age < 30 and yellow card > 3
Get players that age < 30 and yellow card > 3 and red_cards >6
Get players that age < 30 and red_cards card > 3 and scores > 2
Get players that scores < 30 and yellow card > 3 and fouls < 6 and red_cards >2
Get players that scores < 30 and yellow card > 3 and fouls < 6 and red_cards >2 and age > 25
在这种情况下,分配索引的最佳方法是什么?如果我的集合有 6 个字段,就像我的示例中一样,我需要 36 个索引吗? 还是每个索引有一个字段是更好的选择?
【问题讨论】:
-
每个集合的索引不能超过 64 个。但是,建议保持远低于该数字。如果您的数据插入率很高,那么保持较小的数字就更重要了。阅读此docs.mongodb.org/manual/applications/indexes
标签: mongodb performance indexing database