我正在做一个简单的项目。我正在使用 SpringData 和 MongoDB。
创建正常集合的一切都很完美,但现在我必须注册信息,我的意思是日志记录功能。
所以我在 mongo 文档中读到了这个:
上限集合提供了一种高性能的存储方式
将文档记录在数据库中。将对象插入未索引的对象
capped collection 将接近记录到 a 的速度
文件系统。此外,通过内置的 FIFO 机制,您可以
不存在使用过多磁盘空间进行日志记录的风险。
我觉得太棒了!这就是我需要的,但我有疑问。可以用 SpringData 创建这种类型的集合吗???我在 SpringData 文档中找不到任何内容。
有人知道这件事吗?
谢谢
I'm working on a simple project. I'm using SpringData and MongoDB.
Everything is perfect creating normal collections, but now I have to register information, I mean a logging functionality.
So I read this in the mongo documentation:
Capped collections provide a high-performance means for storing
logging documents in the database. Inserting objects in an unindexed
capped collection will be close to the speed of logging to a
filesystem. Additionally, with the built-in FIFO mechanism, you are
not at risk of using excessive disk space for the logging.
I thought great! this is what I need, but I have a doubt. Is posible to create this kind of collections with SpringData??? I couldn't find anything in SpringData documentation.
Someone knows something about this?
Thanks
发布评论
评论(3)
有一个方法
createCollection(…)
采用CollectionOptions
参数,您可以在其中指定要限制的集合:将这些选项公开给
可能是个好主意@Document
注释在构建映射上下文时自动处理它们,但我们通常得到人们的反馈,希望手动处理这些集合设置和索引操作,而不需要太多的自动行为。如果您希望看到支持,请随意打开 JIRA。There's a method
createCollection(…)
taking aCollectionOptions
argument where you can specify a collection to be capped:Might be a good idea to have those options exposed to the
@Document
annotation to automatically take care of them when building the mapping context but we generally got the feedback of people wanting to manually handle those collection setup and indexing operations without too much automagic behavior. Feel free to open a JIRA in case you'd like to see that supported nevertheless.现已弃用。相反,您应该使用以下代码:CollectionOptions options = new CollectionOptions(null, 5000, true)
不要忘记指定大小。有关详细信息,请参阅可尾游标。
is now deprecated. Instead you should use the following code:CollectionOptions options = new CollectionOptions(null, 5000, true)
Don't forget to specify the size. For more info see Tailable Cursors.
如果您有 spring-data 创建的集合(例如:
reservation
),您可以轻松地将其转换为 capped,就像这样:阅读 mongodb 手册:https://docs.mongodb.com/manual/reference/command/convertToCapped/
ps:
@Tailable
注释非常性感,它可以帮助您跟踪该集合的更新并使用反应式编程原理对其更改做出反应If you have collection created by spring-data (for example:
reservation
), you can easily convert it to capped, just like so:read mongodb manual: https://docs.mongodb.com/manual/reference/command/convertToCapped/
ps:
@Tailable
annotation is very sexy, it can help you track updates for that collection and react on it changes using reactive programming principles