ReactiveMongoTemplate .save无法将@compondindex注释添加到集合类中

问题描述

我有一个java类“ Class A”,该对象的类是使用reactMongoTemplate.save操作以响应方式保存在mongoDB中的。

public class A {
 // field 1
 // field 2
 ..
 // field n
}

这一切工作得很好,并将大量数据填充到相应的集合中。

现在,我决定向集合中引入索引,因此将该注释添加到类中

@Compoundindex(name ="collection_index_name",def = "{'field1':1,'field1':-1}",unique=true)

现在添加此注释后,我看到我的mongoDB writer(将数据写入上述mongodb集合的过程)卡住了很长时间(15-20分钟),或者没有进一步处理。 在调试它时,我看到控件达到了我进行ReaciveMongoTemplate.save()操作的地步。但是在执行save react方法后,我只得到以下警告,并且对该集合没有写操作。

Automatic index creation will be disabled by default as of Spring Data MongoDB 3.x.
    Please use 'MongoMappingContext#setAutoIndexCreation(boolean)' or override 'MongoConfigurationSupport#autoIndexCreation()' to be explicit.
    However,we recommend setting up indices manually in an application ready block. You may use index derivation there as well.

    > -----------------------------------------------------------------------------------------
    > @EventListener(ApplicationReadyEvent.class)
    > public void initIndicesAfterStartup() {
    >
    >     IndexOperations indexOps = mongoTemplate.indexOps(DomainType.class);
    >
    >     IndexResolver resolver = new MongoPersistentEntityIndexResolver(mongoMappingContext);
    >     resolver.resolveIndexFor(DomainType.class).forEach(indexOps::ensureIndex);
    > }
    > -----------------------------------------------------------------------------------------

一旦我删除了上面的注释或替换为一个新的空集合,并再次运行相同的代码,我就会立即看到条目被保存。

此行为是否有任何解释?在已经在集合内部填充了很多数据之后,这与向集合添加索引有关吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)