MongoDB上限集合允许的最大大小

时间:2012-11-18 17:53:46

标签: mongodb pymongo

我正在使用一个可以使用的mongodb上限集合。我想将它的大小设置为最大值,因为我不想根据FIFO规则删除最旧的记录。

我希望尽可能长时间地保持数据的生成,同时保留封顶集合的功能。

由于

2 个答案:

答案 0 :(得分:6)

您可以根据需要设置上限集合;只需将create_collectionsize参数设置为足够大的值,以免空间不足。

像这样:

 db.create_collection('captest', capped=True, size=20000000000)

答案 1 :(得分:1)

您可以使用大小(以字节为单位)或最大值(要保留的最大文档数)或两者都创建上限集合:

pymongo - >

self.db.create_collection('system_health_log', capped=True, size=5242880, max=5000)

mongo shell - >

db.createCollection("system_health_log", { capped : true, size : 5242880, max : 5000 } )

在上限收藏中查看更多here

相关问题