Springboot2 + 反应式 + mongo =>Tailable 和 Capped 集合 [英] Springboot2 + reactive + mongo => Tailable and Capped collection

查看:90
本文介绍了Springboot2 + 反应式 + mongo =>Tailable 和 Capped 集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用 Springboot2 尤其是 Reactor (Flux/Mono) 做一些测试.我遇到了问题.

I try to do some tests with Springboot2 espacially with Reactor (Flux/Mono). I'm facing a problem.

当我尝试使用存储库方法时,请检索我使用该方法的所有人员:@尾随Flux findWithTailableCursorBy();

When i try to use a repository method do retrieve all my persons i use that method : @Tailable Flux findWithTailableCursorBy();

但就我而言,我收到该错误

But in my case, i receive that error

Caused by: com.mongodb.MongoQueryException: Query failed with error code 2 and error message 'error processing query: ns=test.person batchSize=2Tree: $andSort: {}Proj: {} tailable cursor requested on non capped collection' on server localhost:27017

当我将我的收藏设置为上限"时,它会起作用

When i set my collection to "capped" it works

db.runCommand( { convertToCapped: 'person', size: 8192 } )

但出于多种原因我不会使用上限集合

But i won't use a capped collection for many reason

  • 无法删除文档(必须删除集合)
  • 不要以编程方式设置此属性

我不知道如何解决这个问题,也许我的代码或选择有误.

I don't know how to resolve this, maybe i'm wrong in my code or choice.

有人可以解释我如何使用仅检索数据库中的新元素吗?

Can someone explain me how to use retrieve only new elements in my DB?

问候

推荐答案

这是设计使然,而不是 Spring Data 的限制.MongoDB 仅在上限集合上支持 Tailable 游标(请参阅 mongodb 参考文档).

This is by design, and not a Spring Data limitation. MongoDB supports Tailable cursors only on capped collections (see the mongodb reference documentation).

如链接文档中所述,您可以选择轮询索引集合以获取新元素(我不知道 Spring Data 中有任何响应式集成).

As explained in the linked document, you can choose to poll an indexed collection for new elements (I’m not aware of any reactive integration for that in Spring Data).

这篇关于Springboot2 + 反应式 + mongo =>Tailable 和 Capped 集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆