Index not updated with springboot

I have an application in java springboot, which is a CRUD application that uses mongodb. The thing is, one of my collections has an index, set by the java code with the tag @Indexed. Now I want to create a second index, but when i tag the second field with @Indexed doesn’t work… I like only the first time the collection is created the indexes too… and then once the collection is already created you can not update the indexed by java code anymore… because when I remove the collection, I set the second index and after the deploy, the second index is properly created…

Any suggestion?? i can’t remove the collections, and i want to update the indexes by code…


Hello @Anna_Barrera_Quintanilla, welcome to the MongoDB community forum!

You can use the Spring Data MongoDB API method MongoTemplate#indexOps to create an index on a collection field programmatically.

1 Like