[英]How to stream from a capped collection with Spring data-mongodb-reactive
[英]Creating a capped collection using Spring data MongoDB @Document
我正在使用MongoDB尝试spring-data中的反应支持。 我使用的是spring-boot 2.0.0。
通常我会在我的项目中写一个这样的域对象:
@Document
public class PriceData {
......
}
使用这个spring-data,它将在MongoDB中创建一个名为priceData的集合。 如果我想自定义它,那么我会使用collection
属性:
@Document(collection = "MyPriceData")
由于我想尝试MongoDB的反应支持,我想创建一个上限集合,以便我可以使用@Tailable
游标查询。
我可以在我的MongoDB数据库中创建一个封顶集合作为指定在这里 :
CollectionOptions options = new CollectionOptions(null, 50, true);
mongoOperations.createCollection("myCollection", options);
要么
db.runCommand({ convertToCapped: 'MyPriceData', size: 9128 })
如果我使用一些外部MongoDB数据库,我可以运行此命令一次,这不是一个大问题。 但是如果我使用嵌入式MongoDB,那么我会把它放在一个每次启动时都要执行的类中。
无论哪种方式,我都会在第一次请求之前创建一个集合。 所以我想知道是否有办法,我可以指定spring-data-mongodb我需要一个上限集合而不是常规集合。 不幸的是@Document
对这种情况没有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.