Search code examples
javamorphia

How can I migrate the ensureIndexes with Morphia from 1.6 to 2.4?


I am migrating Morphia from 1.6 to 2.4.

We are running the ensureIndexes on our application starting.

But, We caught warning messages as follow.

Mapper#map is configured in the config file and should not be called directly.

Then, I read the morphia document as follow. https://morphia.dev/morphia/2.4/javadoc/dev/morphia/Datastore.html#ensureIndexes()

I can see that I can config a ensureIndexes by a config file.

How can I config the ensureIndex by file?


Solution

  • You can create the MorphiaConfig and programmatically and configure starting with MorphiaConfig.load(). If you go the config file route, you can set morphia.apply-indexes=true. The complete file structure can be seen here. The complete configuration docs can be found here