上限集合与队列
Capped collections vs Queues
我想了解什么是上限集合,特别是在 MongoDB 的上下文中,与队列相比有什么区别?
CAPPED mongodb 中的集合是 circular buffer.
的实现
来自官方文档
Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.
Capped 集合将在达到限制时删除最旧的文档,因此如果需要处理来自 Capped 集合的 ALL 个文档,这可能会成为一个问题。
from mongo: Capped collections work in a way similar to circular
buffers: once a collection fills its allocated space, it makes room
for new documents by overwriting the oldest documents in the
collection.
与队列比较:
队列满时不会删除记录(它可能会抛出异常
就像内存不足)
队列可以在出队时删除记录 - 在上限集合中你需要自己删除它
上限集合清理:如果上限集合大小为 40 个文档 - 那么当添加第 41 个文档时 -> 第一个条目被删除
我认为这是最重要的事情 - 欢迎任何评论!
我想了解什么是上限集合,特别是在 MongoDB 的上下文中,与队列相比有什么区别?
CAPPED mongodb 中的集合是 circular buffer.
的实现来自官方文档
Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.
Capped 集合将在达到限制时删除最旧的文档,因此如果需要处理来自 Capped 集合的 ALL 个文档,这可能会成为一个问题。
from mongo: Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.
与队列比较:
队列满时不会删除记录(它可能会抛出异常 就像内存不足)
队列可以在出队时删除记录 - 在上限集合中你需要自己删除它
上限集合清理:如果上限集合大小为 40 个文档 - 那么当添加第 41 个文档时 -> 第一个条目被删除
我认为这是最重要的事情 - 欢迎任何评论!