问题
On the previous version of Spring Boot (2.1.9) everything worked fine. I'd updated it to 2.2.2.RELEASE
(with dependency management plugin used), and have started to get an error:
org.springframework.dao.DataIntegrityViolationException:
Cannot create index for '' in collection 'testDTO' with keys 'Document{{_id=1, version=1}}' and
options 'Document{{name=optimistic_concurrency_idx}}'.;
nested exception is com.mongodb.MongoCommandException:
Command failed with error 67 (CannotCreateIndex): 'Unknown index plugin '1'' on server mongo:27017.
The full response is { "ok" : 0.0, "errmsg" : "Unknown index plugin '1'", "code" : 67, "codeName" : "CannotCreateIndex" }
I'd searched, but didn't find any way to fix it. Along with that, I have messages in logs:
Registering converter from class java.time.LocalDateTime to class java.time.Instant as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
Registering converter from class java.time.Instant to class java.time.LocalDateTime as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
But as I've read here, it's not so important. Also, this logs message doesn't look important as well:
Automatic index creation will be disabled by default as of Spring Data MongoDB 3.x.\n\tPlease use 'MongoMappingContext#setAutoIndexCreation(boolean)' or override 'MongoConfigurationSupport#autoIndexCreation()' to be explicit.\n\tHowever, we recommend setting up indices manually in an application ready block. You may use index derivation there as well.\n\n\t> -----------------------------------------------------------------------------------------\n\t> @EventListener(ApplicationReadyEvent.class)\n\t> public void initIndicesAfterStartup() {\n\t>\n\t> IndexOperations indexOps = mongoTemplate.indexOps(DomainType.class);\n\t>\n\t> IndexResolver resolver = new MongoPersistentEntityIndexResolver(mongoMappingContext);\n\t> resolver.resolveIndexFor(DomainType.class).forEach(indexOps::ensureIndex);\n\t> }\n\t> -----------------------------------------------------------------------------------------\n","component":"org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator
Because I' ve added spring.data.mongodb.auto-index-creation: true
to my application.yml
, but the message is still present because it doesn't have any flag checking.
I've tried to downgrade the spring-data-mongo
(and boot-starter
as well), but it can't configure the context with ClassNotFound
exceptions.
Was anybody faced with this problem? How to solve it?
来源:https://stackoverflow.com/questions/59323365/how-to-fix-mongo-index-creation-after-update-to-srping-boot-2-2