वसंत में
MongoTemplate#indexOps(String collection) . के साथ आप IndexInfo . की सूची प्राप्त कर सकते हैं , MongoDB संग्रह के सूचकांक का प्रतिनिधित्व करता है। चूंकि यह एक नियमित सूची है, इसलिए आप hasItem(Matcher<? super T> itemMatcher) के संयोजन के साथ अपने दावे कर सकते हैं। और hasProperty(String propertyName, Matcher<?> valueMatcher) :
final List<IndexInfo> indexes = mongoTemplate.indexOps("myCollection").getIndexInfo();
assertThat(indexes, hasSize(3));
assertThat(indexes, hasItem(hasProperty("name", is("_id_"))));
assertThat(indexes, hasItem(hasProperty("name", is("index1"))));
assertThat(indexes, hasItem(hasProperty("name", is("index2"))));
assertThat(indexes, hasItem(hasProperty("indexFields", hasItem(hasProperty("key", is("field1"))))));
यदि आपको यह बहुत अपठनीय या अनुपयोगी लगता है तो आप एक कस्टम हैमक्रेस्ट मैचर के साथ बेहतर हो सकते हैं।