首页 > 解决方案 > Spring MongoDB 复合索引覆盖率

问题描述

我有一个包含字段engine, type,的文档manufacturerId。我在 3 个字段上创建了一个复合unique索引,所以我使用以下内容来创建索引。

@CompoundIndex(name = "engine_type_manufacturerId", def = "{'engine' : 1, 'type' : 1, 'manufacturerId': 1}", unique = true)

这样可以避免 3 个字段的组合出现重复条目​​。

继续前进,在我的应用程序中,我有查询,我只能通过engine或搜索engine & type。现在,我的问题是,我之前创建的复合唯一索引是否会涵盖查询的情况,engine或者engine & type我应该为这些情况创建新索引吗?

标签: mongodbspring-bootindexingmongodb-indexes

解决方案


推荐阅读