Announcement Announcement Module
No announcement yet.
Spring-Data does not find IndexFields for Indices created via MongoDB shell Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring-Data does not find IndexFields for Indices created via MongoDB shell


    we are using Spring-Data-Mongo to access our MongoDB from a Java application. In general everything works fine but I encountered one odd behavior.

    When initializing our Repositories in the Java code we use ensureIndex to create indices on the collections. In a unit test we read all indices from the collections as IndexInfo objects and check if those IndexInfo objects contain the fields we want to index in the member indexFields. This also worked fine when we set everything up.

    Now it happened that we had to recreate one of the indices on our production environment, so we dropped it and created it again using the Mongo shell. The system seems to run fine and no issues came up. For consistency reasons we then made the same change to our test and even local environments in the same way. Then we noticed that our unit test for index checking fails because the indexField member is now empty.

    I tried everything I can imagine but as soon as I create an index using the Mongo shell Spring does not deliver any index fields anymore even when I create an index with the identical configuration.

    Can anyone tell me why that happens and if that indicates there is a problem? Is there a way to fix this without having to drop the collection? I was thinking about dropping the index after our next production release and then trigger an insert. On my local machine this created the index the way I expected it and the test succeeds.