Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I define index on inherited fields in MongoDB with Spring Data?

I have a persistent class that extends a parent where some of its fields are defined. With Spring Data Mongo, I can use the @Indexed annotation on persistent fields to create index on the corresponding Collection. However, in the case of inherited fields, I can only access them through the parent class. I could probably put the annotation there but I don't want to create index for a every Collection extending the parent class. Can I potentially use @CompoundIndex (with single value) to work around this?

like image 264
Psycho Punch Avatar asked Oct 20 '25 04:10

Psycho Punch


1 Answers

After doing some local testing, I found out that, yes, I can use @CompoundIndex to workaround this issue.

like image 176
Psycho Punch Avatar answered Oct 22 '25 19:10

Psycho Punch