How to test Mongo indexes in integration tests?
问题 I have a Java method which creates an index on two fields from a Mongo collection. I should get the index info for the collection, then check if the name and fields of the index are correct. What is the cleanest way to write an integration test for this? Would it make sense to use a custom Hamcrest matcher to see if the index is in the collection? 回答1: In Spring With MongoTemplate#indexOps(String collection) you can fetch a List of IndexInfo , representing the indexes of the MongoDB