【发布时间】:2013-09-25 21:03:26
【问题描述】:
考虑 Mongo 的 Compound Indexing 示例:
Example Given the following index:
{ "item": 1, "location": 1, "stock": 1 }
MongoDB can use this index to support queries that include:
- the item field, and
- the item field and the location field, and
- the item field and the location field and the stock field.
MongoDB cannot use this index to support queries that include:
- only the location field,
- only the stock field,
- only the location and stock fields, and
- only the item and stock fields.
是否有比简单的排列更好的最小#索引来支持商品、位置和库存的任何“精确匹配”查询组合?
编辑
为了解决上面缺少的索引,我可以添加Location、Stock、Location-Stock 和Item-Stock 索引。请注意,最后 2 个是复合索引,用于处理我的问题中列出的所有查询。
但是,在尝试处理 N 个字段的所有排列时是否有一般规则?
【问题讨论】:
-
你不能解决这个问题吗?看起来很简单,你只是想让我们为你做数学
-
根据您的适当指责编辑,Sammaye。谢谢你。
-
不要以这种方式存储数据——您需要存储更多的“键/值/类型”,以可能减少可能需要的索引排列数量。
-
@WiredPrairie,请进一步解释。我不关注。
-
我也没有。 :) 作为我正在考虑的解决方案的一部分,我在脑海中混合了另一个数据库的功能,形成了一种邪恶/不可能的混合。所以,没关系。