spring-boot - ReactiveMongoTemplate .save 无法将@compondindex 注释添加到集合类
问题描述
我有一个 Java 类“A 类”,其对象以反应方式使用 reactiveMongoTemplate.save 操作保存在 mongoDB 中。
public class A {
// field 1
// field 2
..
// field n
}
这一直工作得很好,并将大量数据填充到相应的集合中。
现在我决定为集合引入索引,因此将此注释添加到类中
@CompoundIndex(name ="collection_index_name", def = "{'field1':1, 'field1':-1}", unique=true)
现在添加此注释后,我看到我的 mongoDB 编写器(将数据写入上述 mongodb 集合的进程)长时间卡住(15-20 分钟)或没有进一步处理任何内容。在调试它时,我看到控制达到了我可以ReaciveMongoTemplate.save()
操作的程度。但是在执行 save 反应方法之后,我只收到以下警告,并且集合没有发生写入。
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);
> }
> -----------------------------------------------------------------------------------------
一旦我删除上述注释或替换为新的空集合,并再次运行相同的代码,我就会看到条目立即被保存。
这种行为有什么解释吗?在集合中已经填充了大量数据之后,这与向集合添加索引有关吗?
解决方案
推荐阅读
- dns - 云无法解析 GCP Cloud DNS 中的 CNAME
- python-3.x - 训练具有不同输入形状的预训练序列模型
- excel - 为什么我在尝试使用 MSXML2.XMLHTTP 对象发送谷歌搜索时突然出错?
- python - 输入图像列表的 CNN 模型输出 [int,int,float] 的列表
- yaml - 如何让 TYPO3 路由增强器正确使用自定义扩展(TYPO 3 v10)
- docker - Kubernetes - 如何在没有 App 永久运行的情况下制作简单的 Linux 容器镜像
- asp.net-mvc - 如何在 mvc razor 页面中将我的所有文本框输入字母更改为大写?
- r - 查找具有特定因子组最小值的行
- flutter - 如何管理颤振应用程序中的选项卡
- emacs - display-buffer 从其他窗口生成缓冲区